Forum Discussion
Incorrect Count DAX Function -- Need help
- 3 years ago
Hi Vijay08V
Sorry for the late reply. The solution is to add a 'Years' table to the model to have all year values from the sample table and create a one-to-many relationship from 'Years' table to Sample table on Year column.
Then use 'Years' table's Year column in SELECTEDVALUE function in the measure and in the Year slicer too.
VOLUME COUNT = CALCULATE(COUNT('Sample'[Number]),'Sample'[YEAR]=SELECTEDVALUE('Years'[YEAR],YEAR(TODAY())))Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Hi Vijay08V
I don't see any Year value from your visuals. Do you have any filter or slicer in the report to select a year?SELECTEDVALUE only returns one distinct value in the current context. If there are more than one distinct values, it returns the alternateResult.
In addition, can you please share some sample data of the table as well as the expected result based on it?
Best Regards,
Community Support Team _ Jing
Yes I have a year filter for the visual. The desired output is to get current year count in the visual if year slicer is not selected and the counts in visual should change upon changing the year filter. Also what I notice is that this issue is occuring only when I add any category in the Legend field.
I was not able to attach the sample pbix file in this thread hence attaching as drive link
https://drive.google.com/file/d/1t2yiufHvwMCbg7V0Vph-JGg2AN-Bh97i/view?usp=drivesdk
- v-jingzhang3 years agoCommunity Support
Hi Vijay08V
Sorry for the late reply. The solution is to add a 'Years' table to the model to have all year values from the sample table and create a one-to-many relationship from 'Years' table to Sample table on Year column.
Then use 'Years' table's Year column in SELECTEDVALUE function in the measure and in the Year slicer too.
VOLUME COUNT = CALCULATE(COUNT('Sample'[Number]),'Sample'[YEAR]=SELECTEDVALUE('Years'[YEAR],YEAR(TODAY())))Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.- Vijay08V3 years agoHelper III
It worked. Thank you very much!