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
aflintdepm
Helper III
Helper III

Count Occurrence in a Column- must be dynamic

I have a column of data with recurring entries.  There are about 10 unique choices, but these can occur an infinite of times.  

 

aflintdepm_0-1677795358954.png

I would like to count how many times each reason appears, but have the calculation add Reason 4 or 5 whenever they are added in the future.

 

Ideally, I would want something like this (at a minimum) in a matrix

aflintdepm_1-1677795466984.png

I would also like to be able to calculate percent of total to visualize in a pie.

I feel like, once I can work out how to get the count, I can expand to other presentations.

 

I tried this formula, but it is giving me a blank matrix when I add it as a value.

Count of Reason = CALCULATECOUNTROWS('ExampleTable'),FILTER('ExampleTable','ExampleTable'[Reason] = SELECTEDVALUE('ExampleTable'[Reason])))
 
This seems like it should be easier...
Thanks
1 ACCEPTED SOLUTION
bharath_v
Resolver I
Resolver I

Hi @aflintdepm 

I was able to simulate the output without using any DAX.

 

In matrix visual, do these steps:

Rows -> Date

Columns -> Reason

Values -> Count of Reason (not distinct)

           -> Count of Reason (Show value as percentage of total)

 

Rename the value headers accordingly.

Output:

bharath_v_1-1677798150281.png

Let me know if I am missing something. 

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
aflintdepm
Helper III
Helper III

Thank you @Padycosmos , @Ashish_Mathur , and @bharath_v 

Apparently, Power BI decided to throw me a real curve ball.  The tab I was working in appears to have been corrupted.  I started testing with other visuals that I knew worked in other tabs and those returned "blank" as well.  I finally just deleted the whole tab and made a new one and now everything works as expected.  Spent 3 days trying to figure this out....🤕

Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and SIngle) from the Date column of the Data Table to the Date column of the Calendar Table.  To the matrix visual, drag Date from the Calendar Table to row labels and Reason to Column labels.  Write this measure and drag it to the visual

Count = countrows(Data)

Count (%) by date = calculate([Count],all(calendar))

Count (%) by Reason = calculate([Count],all(Data[Reason]))

Format the last 2 measures as %.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur 

This got me closer, but is not working properly

  1. I had a calendar table identified already, so that part worked.  However, when I add it to the matrix, it retruns dates that are not in the fact table.  My data is only from 12/29/22, but the matrix is returning values from 6/1/20
  2. Only the Count % by Date is returning results.  The % Count by Reason is blank in all columns
  3. The Count % by Date is returning multiple results >100%, so something is wrong there

I know it is difficult to assist without sample data to manipulate, so I truly appreciate your help.

I will need to see your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
bharath_v
Resolver I
Resolver I

Hi @aflintdepm 

I was able to simulate the output without using any DAX.

 

In matrix visual, do these steps:

Rows -> Date

Columns -> Reason

Values -> Count of Reason (not distinct)

           -> Count of Reason (Show value as percentage of total)

 

Rename the value headers accordingly.

Output:

bharath_v_1-1677798150281.png

Let me know if I am missing something. 

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I'm not sure you're missing anything, but I definitely am

aflintdepm_0-1677798754803.png

Not sure what I'm doing wrong

Can you check on the filters section to see if you are filtering data?

No slicers on the page, no filters on the visual, as far as I can tell

aflintdepm_0-1677939581719.png

Does it have anything to do with the fact that the Reason column is text?

Padycosmos
Solution Sage
Solution Sage

Hope this helps:

Padycosmos_0-1677797367018.png

 

Thank you for the example- unfortunately, I'm getting a blank matrix.  Can you please describe which value you put in Row/Column/Value?  Thank you

Dates in the Row, and Category in Column and Measure in values

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!

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.

Top Solution Authors
Top Kudoed Authors