Help Needed with Filtered Count Expression

Hi all,

Can anyone clue me in on what I'm doing wrong with this expression? My goal was to get a percentage of an item marked "dry" (the "Action") out of the total number of inspections for that item.

Another way to say it: I'm trying divide a count of a filtered ref ("history2") into a total count of ref rows.

Ryan_Wagner_0-1669755683481.png

 

I'd appreciate anyone's insight! Formula works but gives me all kinds of strange numbers, none of which are remotely correct.

Solved Solved
0 19 402
1 ACCEPTED SOLUTION

You are wildly mistaken about the role of _thisrow. It's function is to resolve any ambiguity of context. Imagine you're in the record of table1 with a column [category], and you're selecting across table2 by matching to its own [category] column. Using FILTER( table2 , [category]=[category] ) is going to return all records in the table, because every record's [category] column equals it's own [category] column. But you're wanting to match it to the current table1 record's [category], so you use _thisrow to specify which context to pull that column from, with FILTER( table2 , [category]=[_THISROW].[category] ).

No, your new SELECT expression is still selecting across the entire table, it is doing the same thing as before.

I mentioned that you can select across your [Related...] column, which you didn't seem to catch. You'd need to do one of the following, which are equivalent, but the former is more efficient.

COUNT(SELECT( [Related History2s][Asset Number] , [Action]="Dry" ) )

COUNT(FILTER( History2 , AND( [Action]="Dry" , [ref-column] = [_THISROW] ) ) )

View solution in original post

19 REPLIES 19

(And here's the current output, which is incorrect):

Ryan_Wagner_0-1669755960610.png

 

Steve
Platinum 4
Platinum 4

Thanks, Steve. I always value your contributions. 

I gave those fixes a try, but unfortunately it's performing the same way.  Not sure if there is more info I can provide. I assumed the problem was somewhere in my attempt to count a filtered reference and divide into another filtered reference...

For illustration, here's a "3 out of 4 times were dry" scenario that I want to give me a "75%" but is outputting 100%.

Ryan_Wagner_0-1669761823482.png

 

Try

COUNT( FILTER("history2",[Action]="Dry") )
/
COUNT( FILTER("history2",ISNOTBLANK([Action]) )

without [_THISROW].

Screen Shot 2022-11-30 at 7.42.27 AM.png

Thank you. That seems to have gotten me closer? At least I'm getting different numbers now, but the math is still not working out...This one in the screenshot should be another "75%", but is showing as 66%...

This is strange.

This one should be 100%...

Screen Shot 2022-11-30 at 7.47.53 AM.png

Please give this a try by using the hint already give by @Steve in his reply

COUNT( FILTER("history2",[Action]="Dry") )*1.00
/
COUNT( FILTER("history2",ISNOTBLANK([Action]) )*1.00

Thanks, @Suvrutt_Gurjar . I tried that, too, but it's performing the same way. Still not working. I am using a "percent" column type, but I also tried this as a "number" column. 

Wondering if I should give up on this idea...

Is it possible that my filter is counting ALL the rows in the "history2" table that have been labeled "dry?" The problem seems to be with how it is looking up the reference, unless I am wrong...

Thank you for the update. In that case , you may want to once more verify  your expression whether it is resulting in correct number of numerator and denominator values. You could check each separately in a VC.  I think 66% means possibly 2/3 instead of expected 75 % which 3/4 ( your first result) . Second result you are expecting 100% (3/3) but the result shows possibly 2/3 ( 66%) 

So maybe numerator or denominator somehow are not getting all the record values that they should get as per your expectation.

That is a great idea, thanks @Suvrutt_Gurjar . 

I removed the division part and just tried to get a count of all the "dry" for a given row. Its still giving me (what I assume) is the total count of ALL "dry" for the whole table...

Screen Shot 2022-11-30 at 11.28.44 AM.png

I also tried it without "_THISROW"...

Yes of course it is giving a count for the entire table, you haven't told it to do otherwise. Is it a parent-child ref situation? If so, instead of FILTER(table...) you can do SELECT( [Related table][key-column]...)

I thought the "this row" component would isolate the results...Yes, it is a parent-child ref. I haven't had a lot of success navigating the SELECT function, but I'm definitely open to trying again...I hope I at least explained what I was after well enough.

So here's what I cooked up to try SELECT:

Screen Shot 2022-11-30 at 1.44.14 PM.png

But, same wild results. This row should read as "2," at least in theory, no?

Screen Shot 2022-11-30 at 1.44.55 PM.png

The "AssetNumber" is my key, by the way.

You are wildly mistaken about the role of _thisrow. It's function is to resolve any ambiguity of context. Imagine you're in the record of table1 with a column [category], and you're selecting across table2 by matching to its own [category] column. Using FILTER( table2 , [category]=[category] ) is going to return all records in the table, because every record's [category] column equals it's own [category] column. But you're wanting to match it to the current table1 record's [category], so you use _thisrow to specify which context to pull that column from, with FILTER( table2 , [category]=[_THISROW].[category] ).

No, your new SELECT expression is still selecting across the entire table, it is doing the same thing as before.

I mentioned that you can select across your [Related...] column, which you didn't seem to catch. You'd need to do one of the following, which are equivalent, but the former is more efficient.

COUNT(SELECT( [Related History2s][Asset Number] , [Action]="Dry" ) )

COUNT(FILTER( History2 , AND( [Action]="Dry" , [ref-column] = [_THISROW] ) ) )

Thanks. Apologies for missing the point. I don't consider myself an expert.

Top Labels in this Space