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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Kez_nz
Frequent Visitor

Counting number of times a value appears and tallying

Hi, I'm having a bit of trouble with DAX

Say if I have a dataset like this:

 

date,name
2020-05-04,Snake
2020-05-04,John
2020-05-04,John
2020-05-04,John
2020-05-04,James
2020-05-05,Liquid
2020-05-05,Snake
2020-05-06,Snake
2020-05-06,Snake
2020-05-06,Snake

 

I want to calculate how many times each names appears, then 'tally' those numbers. So in the above dataset, James & Liquid appeared in the dataset once, John appeared three times, and Snake appeared five times.

This is my desired output:

Capture.PNG

When using the solution from @ryan_mayu 

Column = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[NAME]=EARLIER('Table'[NAME])))

If the dates get adjusted with a slicer, the values do not get updated (i.e. if a date slicer was set to 2020-05-05 onwards, 'Snake' would still show as appearing five times rather than four.

Capture2.PNG

Thanks

-Edited to show problem with slicer.

4 REPLIES 4
amitchandak
Super User
Super User

ryan_mayu
Super User
Super User

@Kez_nz 

maybe you can create a column.

Column = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[NAME]=EARLIER('Table'[NAME])))

1.PNG2.PNG

in your sample data, john appears 3 times, james and liquid appear once and snake appears 4 times





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu 

I've went and tried it on my own data set and it worked until I changed the dates using a slicer.

I think I've found the problem: 

If I add a row so that 'Snake' appears five times instead of four:

date,name
2020-05-04,Snake
2020-05-04,John
2020-05-04,John
2020-05-04,James
2020-05-04,John
2020-05-05,Snake
2020-05-05,Liquid
2020-05-06,Snake
2020-05-06,Snake
2020-05-06,Snake

If I shift the slicer to 2020-05-05, 'Snake' should now only be in there four times instead of five. However the graph still shows it as five:

Capture2.PNG

Is there any way to fix this?

@Kez_nz 

I think measures can't drag to x-aixs field. Let's see if anyone else can provide better solution for you.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.