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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KvO88
Frequent Visitor

Check event occurred within set time of previous event of same unique ID

I have a list with unique system ID's who require periodic Preventive Maintenance. I would like to know whether for that same system ID there has been a Corrective Maintenance within one month after the Preventive Maintenance. So in the example table below, I would like to identify the case types in red, those are corrective maintenance cases that occured within a month after a preventive maintenance. How do I make this identification?

 

System IDCase TypeDate
1Preventive Maintenance01/Jan/24
2Preventive Maintenance01/Jan/24
3Preventive Maintenance01/Feb/24
4Preventive Maintenance01/Feb/24
1Corrective Maintenance25/Jan/24
5Preventive Maintenance01/Mar/24
6Preventive Maintenance01/Apr/24
2Corrective Maintenance02/Feb/24
3Corrective Maintenance17/Feb/24
7Preventive Maintenance01/Apr/24
8Preventive Maintenance01/May/24
9Preventive Maintenance01/May/24
5Corrective Maintenance02/Jun/24
6Corrective Maintenance08/Apr/24
6Corrective Maintenance12/Jun/24
2 ACCEPTED SOLUTIONS

Hi @KvO88 ,

 

I apologize for ignoring the extra condition, please try the following expression:

Measure = var _t =ADDCOLUMNS('Table',"A",MINX(FILTER(ALL('Table'),[Case Type]="Preventive Maintenance"&&[System ID]=EARLIER([System ID])),[Date]))
var _t2 =DATEDIFF(MINX(_t,[A]),SELECTEDVALUE('Table'[Date]),DAY)
RETURN IF(_t2>0&&_t2<30&&MAX('Table'[Case Type])="Corrective Maintenance","red","")

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Hi @KvO88 ,

 

On top of that, add a measure:

vtianyichmsft_0-1714031998105.png

Measure 2 = 
SUMX(ALLSELECTED('Table'),[Measure])

 

Best regards,
Community Support Team_ Scott Chang

View solution in original post

7 REPLIES 7
KvO88
Frequent Visitor

@v-tianyich-msft Thanks so much, this already helps a lot. 

There is one thing that I still run in to, does the measure takes into account that I only want to see when a corrective maintenance is within a month after a preventive maintenance

It looks like it checks all lines, despite the Case type.  Thanks in advance for your help!

Hi @KvO88 ,

 

I apologize for ignoring the extra condition, please try the following expression:

Measure = var _t =ADDCOLUMNS('Table',"A",MINX(FILTER(ALL('Table'),[Case Type]="Preventive Maintenance"&&[System ID]=EARLIER([System ID])),[Date]))
var _t2 =DATEDIFF(MINX(_t,[A]),SELECTEDVALUE('Table'[Date]),DAY)
RETURN IF(_t2>0&&_t2<30&&MAX('Table'[Case Type])="Corrective Maintenance","red","")

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

@v-tianyich-msft Thanks! This works 😃 One additional question, how can I convert this measure so that I get the counts of the number of Corrective Maintenances that occured within a month after Preventive?

Hi @KvO88 ,

 

Try the following expression:

vtianyichmsft_0-1714027891048.png

 

Measure = var _t =ADDCOLUMNS('Table',"A",MINX(FILTER(ALL('Table'),[Case Type]="Preventive Maintenance"&&[System ID]=EARLIER([System ID])),[Date]))
var _t2 =DATEDIFF(MINX(_t,[A]),SELECTEDVALUE('Table'[Date]),DAY)
RETURN IF(_t2>0&&_t2<30&&MAX('Table'[Case Type])="Corrective Maintenance",COUNTROWS('Table'),"")

 

 Best regards,
Community Support Team_ Scott Chang

@v-tianyich-msft Thank you for you quick replies! I really appreciate it. 

If I use a Card visual with this measure, I do not get a result....

Hi @KvO88 ,

 

On top of that, add a measure:

vtianyichmsft_0-1714031998105.png

Measure 2 = 
SUMX(ALLSELECTED('Table'),[Measure])

 

Best regards,
Community Support Team_ Scott Chang

v-tianyich-msft
Community Support
Community Support

Hi @KvO88 ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1713943476900.png

Measure = var _t =ADDCOLUMNS('Table',"A",MINX(FILTER(ALL('Table'),[System ID]=EARLIER([System ID])),[Date]))
var _t2 =DATEDIFF(MINX(_t,[A]),SELECTEDVALUE('Table'[Date]),DAY)
RETURN IF(_t2>0&&_t2<30,"red","")

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.