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
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
Impactful Individual
Impactful Individual

@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
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.

Top Solution Authors