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