Forum Discussion
Filtering table with date
- 4 years ago
Calling a measure inside of an iterator like FILTER means a context transition happens that transforms all of the row context into filter context, so that even though [Last date] removes the Date filter context, all of the other column values in that row are still being applied as filter context, in which case you aren't getting the max over the whole table as you expect.
Often, it's easier to sidestep the problem using variables. This also has the advantage of only calculating that measure once instead of for each row of the table you're filtering.
Test Case Step-Blocked-Last = VAR LastDate = [Last date] RETURN CALCULATE ( COUNT ( 'PH_TestCaseStep'[Test Case Step Status] ); 'PH_TestCaseStep'[Date] = LastDate; 'PH_TestCaseStep'[Test Case Step Status] = "Blocked" )Depending on how you want the measure to behave, you may want to keep existing filters on the table rather than replace them. In that case, use
Test Case Step-Blocked-Last = VAR LastDate = [Last date] RETURN CALCULATE ( COUNT ( 'PH_TestCaseStep'[Test Case Step Status] ); KEEPFILTERS ( 'PH_TestCaseStep'[Date] = LastDate ); KEEPFILTERS ( 'PH_TestCaseStep'[Test Case Step Status] = "Blocked" ) )
Try
FILTER('PH_TestCaseStep'; 'PH_TestCaseStep'[Date]=[Last date] && 'PH_TestCaseStep'[Test Case Step Status]="Blocked")
Not sure if it will work as I don;t have a good test case to try it on to hand
Thanks for your reply.
The below measure aimed to calculate from the table all testcases happend on the [Last date]. Even this very simple filtering does not work, so I assume that a measure can't be used in the FILTER function. May be I am wrong...
- PaulDBrown4 years agoCommunity Champion
You need to wrap the table for the FILTER in ALL, as I suggested in my previous post