Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PBI5851
Helper V
Helper 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 5
Icey
Community Support
Community Support

Hi @PBI5851 ,

 

Is this problem solved?

 

 

Best Regards,

Icey

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. 

az38
Community Champion
Community Champion

Hi @PBI5851 

if you return __MaxValue what do you see in card visual?

ActiveCount =

var __MaxValue = [DateValue]
Return
__MaxValue 

It might be affected by ALLSELECTED()

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 When returning the __Maxvalue, i get the correct date i.e the last date as per the date slicer. 

az38
Community Champion
Community Champion

@PBI5851 

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]) )​

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.