Forum Discussion
PBI5851
6 years agoHelper V
Incorrect data using var, but correct when display as a table
Hello,
I am trying to retrieve a count from table where the filter is on the date Slicer. So the active count is the count(*) from the Product table for that specific date.
DateValue = CALCULATE(MAX(Datetable[Date]),ALLSELECTED(Datetable[Date]))
ActiveCount =
var __MaxValue = [DateValue]
Return
CALCULATE(COUNT(Product[ID]), Product[Shipdate]= __MaxValue )
When i display the above measure as a card, i get an incorrect number. I know it is incorrect, because (1) when i run the query against the DB in sql , i get the correct number and (2) when i display the Product in a table in Power BI, and filter based on the specific date, the count (in total) is exactly matching the DB. Not sure what i'm missing. I do not have duplicate in the ID on the product table.
Please help.
5 Replies
- az38Community Champion
try to use ALL() or ALLSELECTED() also
ActiveCount = var __MaxValue = [DateValue] Return CALCULATE(COUNT(Product[ID]), Product[Shipdate]= __MaxValue, ALL(Product) )or
ActiveCount = var __MaxValue = [DateValue] Return CALCULATE(COUNT(Product[ID]), Product[Shipdate]= __MaxValue, ALLSELECTED(Product[Shipdate]) )
- IceyCommunity Support
- PBI5851Helper V
Almost. using the "ALL " in the calculate syntax works. But unfortunately, it seems to not being affected by the Category slicer.
So when i change the date values using the slicer the count i get for min and max is correct. But when i change the filter on the Category slicer which controls the page, the min and max dont change. They remain the same as mentioned above.