Repository navigation
count with filter?
#4384
Replies: 4 comments
|
Something like the following? from [{a=0.1}, {a=0.2}, {a=0.3}, {a=1}, {a=2}, {a=3}]
derive b = case [a < 1 => 0, true => a]
group b (
aggregate {c = count this}
)I've just used "0" instead of "Too small". Also, ignore the odd factor of 10 in the values of |
|
Sorry, that's not quite what I meant... I have described the problem badly. I have a table with three fields: ZoningDistrict, MinimumLotSize, and ActualLotSize. (Many lots in a zoning district may be smaller than the "legally allowed minimum" because they are grandfathered.) I want to group by District, and have a result that shows:
The result might look like:
I see how to use a |
|
How about this? from [{a=0.1, d=1}, {a=0.2, d=1}, {a=0.3, d=2}, {a=1, d=1}, {a=2, d=2}, {a=3, d=3}]
derive b = case [a < 1 => 1, true => 0]
group d (
aggregate {count_ = count this, too_small = sum b}
)Or in one go: from [{a=0.1, d=1}, {a=0.2, d=1}, {a=0.3, d=2}, {a=1, d=1}, {a=2, d=2}, {a=3, d=3}]
group d (
aggregate {
count_ = count this,
too_small = sum case [a < 1 => 1, true => 0]
}
) |
|
Yes, indeed! For my future information: It appears that |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I
derivea field in my table with acasestatement that sets it to "Too big" or "Too small". I want to summarize and produce a count of all rows, plus a count of the rows with "Too small".(Alternatively, I could just embed the filter criteria in the(that won't work...)countwithout the addition of an extra column...)What's the "PRQL Way" to do this? Thanks.
Solution: derive a column with a value of 1 for "Too small" and 0 otherwise; use
sumto count those rows, andcount thisfor the full set.All reactions