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
MarcLykke
Frequent Visitor

How to count cases with matching person-id's and other conditions

Hi everyone

 

I am trying to count the number of cases with matching person-id's and several other conditions.

 

I have one table consisting of all the cases. Each person could have had several cases over time.

 

My mission is to calculate the total case length of each person - but only if the interval between the recent start date and the last end date is less than 1 year. 

 

Example below: 
The new column should reflect the total case length of each active case. There is less than a year between the start date of person 1's recent case and the last end date of the latest case. Therefore the total case length of this case is DATEDIFF(10/11-2020, TODAY).

In the case of person 2 on the other hand, there is more than a year between the recent start date and the latest end date. Therefore the total

 

I hope you guys can help me with this one.

Case idPerson idStart dateEnd dateStatusTotal case length (new)
1110/11-202004/02-2021ClosedDATEDIFF(10/11-2020, 04/02-2021)
2105/05-2021 ActiveDATEDIFF(10/11-2020, TODAY())
3203/02-201905/10-2019ClosedDATEDIFF(03/02-2019, 05/10-2019)
4201/01-2021 ActiveDATEDIFF(01/01-2021, TODAY())
1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi, 

Here is one way to do this (I assume here you want do display the result in a visual).
Start data:

ValtteriN_0-1639392097282.png


Calculated column:

Datediff_T = IF('Datediff'[Edate]=BLANK(),DATEDIFF('Datediff'[SDate],TODAY(),DAY),DATEDIFF('Datediff'[SDate],'Datediff'[Edate],DAY))
Filter measure: 
Datediff filter = IF(DATEDIFF(MAX('Datediff'[EDate]),MAX('Datediff'[Sdate]),DAY)<365,1,0)

 

End result (Here I placed the filter measure to filters):

ValtteriN_1-1639392199649.png


I hope this helps to solve your issue and if it does consider accepting this as a solution!

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
BeaBF
Super User
Super User

@MarcLykke Hi!

You can calculate a column like this:

 

CASE = IF(Tabella[Status] = "Closed", DATEDIFF(Tabella[Start date], Tabella[End date], DAY), DATEDIFF(Tabella[Start date], TODAY(), DAY))
 
"DAY" in the DATEDIFF function, it can be any interval you want to calculate the difference, days, months, years.
 
I hope that's what you wanted, otherwise feel free to answer me.
B.
ValtteriN
Super User
Super User

Hi, 

Here is one way to do this (I assume here you want do display the result in a visual).
Start data:

ValtteriN_0-1639392097282.png


Calculated column:

Datediff_T = IF('Datediff'[Edate]=BLANK(),DATEDIFF('Datediff'[SDate],TODAY(),DAY),DATEDIFF('Datediff'[SDate],'Datediff'[Edate],DAY))
Filter measure: 
Datediff filter = IF(DATEDIFF(MAX('Datediff'[EDate]),MAX('Datediff'[Sdate]),DAY)<365,1,0)

 

End result (Here I placed the filter measure to filters):

ValtteriN_1-1639392199649.png


I hope this helps to solve your issue and if it does consider accepting this as a solution!

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

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.