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
anastasia23
Regular Visitor

Create DAX to count number of cases per month in PowerBI

Hi everyone,

 

In my dataset I have the case number, repair arrived date and repair finished date.

I want to create 2 different measures in order to count how many cases arrived per month and how many cases finished per month.c

I used the following measure to calculate the number of cases that arrived per month, but I see the same number of cases for all the months. Could anyone help me?

 

Monthly cases arrived = VAR StartDate = DATE(2022,11,1) VAR EndDate = DATE(2023,5,8) return CALCULATE(COUNT('All cases'[Case Number]), 'All cases'[Repair Arrived Date]>= StartDate, 'All cases'[Repair Arrived Date]<= EndDate, DATESBETWEEN('Date'[Date], StartDate, EndDate))

 

I try to count the number of cases arrived and finished per month

 

Thank you.enter image description here

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @anastasia23 ,

 

Please try:

First create a Date table:

vjianbolimsft_0-1685344310904.png

Then apply these measures:

Monthly cases arrived = 
CALCULATE(DISTINCTCOUNT('All cases'[Case Number]),FILTER('All cases',[Repair Arrived Date]>=MIN('Calendar'[Date])&&[Repair Arrived Date]<=MAX('Calendar'[Date])))

Monthly cases finished = 
CALCULATE(DISTINCTCOUNT('All cases'[Case Number]),FILTER('All cases',[Repair Finished Date]>=MIN('Calendar'[Date])&&[Repair Finished Date]<=MAX('Calendar'[Date])))

vjianbolimsft_1-1685344369256.png

Final output:

vjianbolimsft_2-1685344384611.png

Best Regards,

Jianbo Li

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

2 REPLIES 2
v-jianboli-msft
Community Support
Community Support

Hi @anastasia23 ,

 

Please try:

First create a Date table:

vjianbolimsft_0-1685344310904.png

Then apply these measures:

Monthly cases arrived = 
CALCULATE(DISTINCTCOUNT('All cases'[Case Number]),FILTER('All cases',[Repair Arrived Date]>=MIN('Calendar'[Date])&&[Repair Arrived Date]<=MAX('Calendar'[Date])))

Monthly cases finished = 
CALCULATE(DISTINCTCOUNT('All cases'[Case Number]),FILTER('All cases',[Repair Finished Date]>=MIN('Calendar'[Date])&&[Repair Finished Date]<=MAX('Calendar'[Date])))

vjianbolimsft_1-1685344369256.png

Final output:

vjianbolimsft_2-1685344384611.png

Best Regards,

Jianbo Li

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

 

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

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.