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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
superhayan
Helper I
Helper I

COUNT DAX with Date Conditions

Hello all, I am stuck in a COUNT DAX with date conditions and hopefully the experts here can give me a helping hand.

 

I have a table of compliance cases which only has 4 columns: Case ID, Case Create Date, Case Close Date, Current Status. My ultimate goal is to plot a line chart with Month as x-axis and 2 trend lines showing in each month, how many cases are closed and how many are still in backlog (created but not yet closed in that month). An example of the table is shown below. Sorry that I cannot access to any cloud drive with work computer hence I cannot share any example data.

Compliance Case IDCase Create DateCase Close DateCurrent Status
101/05/202201/08/2022Closed
201/11/2022 Waiting for info
301/03/202301/03/2024Closed
401/04/202301/04/2024Closed
501/05/2023 In Progress
601/07/202301/01/2024Closed
701/10/2023 In Progress
801/01/2024 In Progress
901/03/202401/05/2024Closed
1001/04/2024 In Progress
1101/04/2024 Waiting for info

 

I have also created a Calendar table and linked it to the Case Close Date with a 1:many relatioship and added a column [Date_Month] to show the mmmyy of each date. I have managed to get the closed cases line with below measure. This measure works well when I pull it as the y-axis trend line with 'Calendar'[Date_Month] as x-axis. 

 

Count_Closed = CALCULATE(COUNT('Compliance'[Case ID]),'Compliance '[Current Status]= "Closed")
 
However I don't know how to get the backlog trendline. I believe it is the sum of below 2 measures (but there might be other calculation methods):
1) Count of cases that are created already in each month on the x-axis, Current Status <> Closed 
2) Count of cases that are created already in the each month on the x-axis, Current Status = Closed but not yet closed in that month on x-axis. 
 
Thanks for helping in advance!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks @JamesFR06  for the quick reply!

 

Hi @superhayan ,

(1) My test data is the same as yours.

vtangjiemsft_0-1716797871061.png

(2) We can create measures.

Count_backlog = COUNTROWS(FILTER(ALLSELECTED('Compliance'),[Case Create Date]<=MAX('DateTable'[Date]) && [Current Status] <> "Closed"))
Count_Closed = CALCULATE(COUNT(Compliance[Compliance Case ID]),FILTER(ALLSELECTED('Compliance'),'Compliance'[Case Close Date]=MAX('DateTable'[Date]) && 'Compliance'[Current Status]="Closed"))

(3) Then the result is as follows.

vtangjiemsft_1-1716797949873.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

3 REPLIES 3
Anonymous
Not applicable

Thanks @JamesFR06  for the quick reply!

 

Hi @superhayan ,

(1) My test data is the same as yours.

vtangjiemsft_0-1716797871061.png

(2) We can create measures.

Count_backlog = COUNTROWS(FILTER(ALLSELECTED('Compliance'),[Case Create Date]<=MAX('DateTable'[Date]) && [Current Status] <> "Closed"))
Count_Closed = CALCULATE(COUNT(Compliance[Compliance Case ID]),FILTER(ALLSELECTED('Compliance'),'Compliance'[Case Close Date]=MAX('DateTable'[Date]) && 'Compliance'[Current Status]="Closed"))

(3) Then the result is as follows.

vtangjiemsft_1-1716797949873.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

JamesFR06
Resolver IV
Resolver IV

Hi,

 

Hope this is what you want :

JamesFR06_0-1716483374092.png

CreatedOC = DISTINCTCOUNT('Table (2)'[Compliance Case ID])
Openprjct =
Var mindate=min('Date'[Date])
Var Maxdate=Max('Date'[Date])
var result=countrows(filter('Table (2)','Table (2)'[Case Create Date]>=Mindate&&'Table (2)'[Case Create Date]<=Maxdate&&'Table (2)'[Current Status]="Closed"&&'Table (2)'[Case Close Date]>Maxdate))
return
result

Thanks for your reply but sadly it gives a blank line chart. I pulled the formula to a Card visual and it showed "--". I am suspecting its because the x-axis (calendar) is related to Case Close Date and only cases that are "Closed" has a close date, so when we only count NON-Closed cases so it returns nothing? 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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