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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
n00b_90
Frequent Visitor

count number of occurences in measure

Hi! 

 

I am totally lost in how to count number of occurences in a measure and display it in a stacked bar chart. 

 

I have a result that looks like this: 

 

datediffminutes.PNG

 

Appointment_minutes is based on this measure: 

appointment_minutes = DATEDIFF(min(Appointment[Appointment Start Date]);max(Appointment[Appointment End Date]);MINUTE)
 
How do I count the frequencies of the appointment_minutes, group them by appointment_minutes and display the results in a stacked bar chart?

 

diagram.PNG

 

I am new to Power BI, so there might be a pretty simple and straight forward solution that I can't think of.. 

 

Hope somebody can help me! 🙂 

 

Kind regards, 

S

 

 

1 ACCEPTED SOLUTION
tex628
Community Champion
Community Champion

360 = 
COUNTROWS(
    FILTER(
SUMMARIZE(
    Table1,
    Table1[start time],
    Table1[end time],
    "Value" , [duration measure]
),
[Value] = 360
))

Try this and make one for each potential duration. 
image.png


Connect on LinkedIn

View solution in original post

5 REPLIES 5
tex628
Community Champion
Community Champion

Are you able to calculate the duration as a calculated column instead of a measure? 

/ J


Connect on LinkedIn

@tex628 sorry, forgot to mention that this is a live connection. So, the solution has to be conducted in a measure 🙂 

tex628
Community Champion
Community Champion

360 = 
COUNTROWS(
    FILTER(
SUMMARIZE(
    Table1,
    Table1[start time],
    Table1[end time],
    "Value" , [duration measure]
),
[Value] = 360
))

Try this and make one for each potential duration. 
image.png


Connect on LinkedIn

Thank you @tex628 ! I actually had over 75 distinct appointment durations so i crated a calculated column in the cube where i categorized the columns into 9 values, the 9th being "More than 2 hours". I combined the switch and datediff function.

 

Then i used your measure in Power BI and it works! 🙂 

tex628
Community Champion
Community Champion

You will need to create a measure for each potential duration, that counts the amount of occurances for that duration. Then you all of these measures together in the value section of the chart!


Connect on LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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