Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Sign up nowGet Fabric certified for FREE! Don't miss your chance! Learn more
What I want to do is pretty straightforward but all the examples I have tried have not worked so far and I'm stressing a little because I need to complete this today.
I have a table of engine oil samples for heavy mining machinery and a column called "Engine Oil Changed" which indicates if the engine oil was changed when that sample was taken. Now I simply want to find out how many hours the oil had before it was changed. I have a running total column for the hours which works fine. I just need to reset this running total when the "Engine Oil Changed" column is true, noting that I need to have it grouped by "Unit Number".
Is anyone able to provide some code to put into this column?
@justlogmein
Hope it's not too late 🙂
Here is the sample file with the solution https://www.dropbox.com/t/HZEL59KsSFlicaPV
Please use the following code
Fluid Hours Reset when Oil Changed =
IF (
'Sample Data'[Oil Changed] = FALSE ( ),
VAR CurrentDate = 'Sample Data'[Sample Date]
VAR DatesBeforeTable1 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] <= CurrentDate )
VAR DatesBeforeTable2 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] < CurrentDate )
VAR PrevuiousChangesTable = FILTER ( DatesBeforeTable2, 'Sample Data'[Oil Changed] = TRUE ( ) )
VAR PreviousChangeDate = MAXX ( PrevuiousChangesTable, 'Sample Data'[Sample Date] )
VAR ResultTable = FILTER ( DatesBeforeTable1, 'Sample Data'[Sample Date] > PreviousChangeDate )
RETURN
SUMX (
ResultTable,
'Sample Data'[Hours Since Previous Reading]
)
)If you want to include the last change hours with the sum use this code with a very tiny change
Fluid Hours Reset when Oil Changed =
IF (
'Sample Data'[Oil Changed] = FALSE ( ),
VAR CurrentDate = 'Sample Data'[Sample Date]
VAR DatesBeforeTable1 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] <= CurrentDate )
VAR DatesBeforeTable2 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] < CurrentDate )
VAR PrevuiousChangesTable = FILTER ( DatesBeforeTable2, 'Sample Data'[Oil Changed] = TRUE ( ) )
VAR PreviousChangeDate = MAXX ( PrevuiousChangesTable, 'Sample Data'[Sample Date] )
VAR ResultTable = FILTER ( DatesBeforeTable1, 'Sample Data'[Sample Date] >= PreviousChangeDate )
RETURN
SUMX (
ResultTable,
'Sample Data'[Hours Since Previous Reading]
)
)
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 7 | |
| 4 | |
| 4 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 9 | |
| 7 | |
| 5 |