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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
BasMinnema90
New Member

Need to count occurrences of each month for different columns

Hi, I'm new here and limited experience with Power BI,

I have a table which is only partially complete containing the month in which a number of different activities have been planned. Missing entries have "Unplanned" instead of a month. Not all activities take place for each ID - if not occuring, this is indicated with n/a.

What I have is something like this (but with hundreds of entries):

IDActivity AActivity BActivity CActivity D
1Januaryn/aJanuaryMarch
2Februaryn/aMarchUnplanned
3UnplannedUnplannedn/aUnplanned
4Januaryn/an/aAugust
5MarchFebruaryUnplannedJune
6 Unplanned Unplannedn/an/a


What I need, is a table that counts the occurence of each month or "unplanned", for each activity, so:

MonthActivity A    Activity BActivity CActivity D
January2010
February1100
March1011
April............
...    
...    
...    
...    

Unplanned

2212


I tried creating a measure for each activity using calculate countrows, activity X = selectedvalue('date table'[month in calendar]), and putting the measures in columns of a table or matrix visual, along with month in calendar from my date table.

This seems to work, but only for the column/activity that has an active connection with the date table, and I can do that only for 1 column.

Can someone help me with a better way to do this?

1 ACCEPTED SOLUTION
vicky_
Super User
Super User

You can generate a new table that has the month names + unplanned, which you can use instead of the month column in the date table. 

To create a new table: 

New Table = UNION(VALUES('Date Table'[Month in Calendar]), {"Unplanned"})

And then change your measure from above to:

Measure = calculate(countrows, activity X = selectedvalue('New table'[Column 1]))



View solution in original post

3 REPLIES 3
BasMinnema90
New Member

Thank you @vicky_ , that seems to work!

But now the table displays the months in random order, do you know how I can make it sequential?

Nevermind, figured it out! Create index column with numbers, then at column tools select months colomn, sort by index column.

vicky_
Super User
Super User

You can generate a new table that has the month names + unplanned, which you can use instead of the month column in the date table. 

To create a new table: 

New Table = UNION(VALUES('Date Table'[Month in Calendar]), {"Unplanned"})

And then change your measure from above to:

Measure = calculate(countrows, activity X = selectedvalue('New table'[Column 1]))



Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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