Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi all,
I am having issue related to total for the below case:
In the below table i need to calculate the time difference:
For each category I have to identify last step based on time field. If last step is "X or Z" then i have to calculate difference of time between max time for step Z and min time for step X. If last step is "Y" then difference of time between max time for step Y and min time for step X.
I created the below measure and it is working at the category level but not showing the correct total:
As you can see total is not correct.
does anyone know how to fix this?
Thanks
Solved! Go to Solution.
alright i believe this should solve your issue.
TimeDifference =
SUMX (
SUMMARIZE (
'Table',
'Table'[Category],
"TimeDiff",
SWITCH (
CALCULATE (
VALUES('Table'[Step]),
FILTER('Table', 'Table'[Time] = MAX('Table'[Time]))
),
"Y",
DATEDIFF (
CALCULATE (
MIN('Table'[Time]),
'Table'[Step] = "X"
),
CALCULATE (
MAX('Table'[Time]),
'Table'[Step] = "Y"
),
SECOND
),
"X",
DATEDIFF (
CALCULATE (
MIN('Table'[Time]),
'Table'[Step] = "X"
),
CALCULATE (
MAX('Table'[Time]),
'Table'[Step] = "Z"
),
SECOND
),
"Z",
DATEDIFF (
CALCULATE (
MIN('Table'[Time]),
'Table'[Step] = "X"
),
CALCULATE (
MAX('Table'[Time]),
'Table'[Step] = "Z"
),
SECOND
)
)
),
[TimeDiff]
)
hi @TaroGulati ,
Your measure is calculating correctly at the category level, but the total is incorrect because Power BI does not sum up row-level calculations for totals in a measure using CALCULATE. Instead, it evaluates the formula in the context of all data, which often leads to incorrect totals.
To ensure the correct total, modify your measure to sum up the values at the row level rather than relying on implicit aggregation:
Total Time Difference =
SUMX(
VALUES('Table'[Category]),
SWITCH (
CALCULATE(VALUES('Table'[Step]),FILTER('Table','Table'[Time] = MAX('Table'[Time]))),
"Y",
DATEDIFF(
CALCULATE ( MIN('Table'[Time]), 'Table'[Step] = "X" ),
CALCULATE ( MAX('Table'[Time]), 'Table'[Step] = "Y" ),
SECOND
),
"X",
DATEDIFF(
CALCULATE ( MIN('Table'[Time]), 'Table'[Step] = "X" ),
CALCULATE ( MAX('Table'[Time]), 'Table'[Step] = "Z" ),
SECOND
),
"Z",
DATEDIFF(
CALCULATE ( MIN('Table'[Time]), 'Table'[Step] = "X" ),
CALCULATE ( MAX('Table'[Time]), 'Table'[Step] = "Z" ),
SECOND
)
)
)
Please cross check for any filters on the page or the visual.
If it still continues to persist. Please share the file in DM if possible so i can have a look at it,
alright i believe this should solve your issue.
TimeDifference =
SUMX (
SUMMARIZE (
'Table',
'Table'[Category],
"TimeDiff",
SWITCH (
CALCULATE (
VALUES('Table'[Step]),
FILTER('Table', 'Table'[Time] = MAX('Table'[Time]))
),
"Y",
DATEDIFF (
CALCULATE (
MIN('Table'[Time]),
'Table'[Step] = "X"
),
CALCULATE (
MAX('Table'[Time]),
'Table'[Step] = "Y"
),
SECOND
),
"X",
DATEDIFF (
CALCULATE (
MIN('Table'[Time]),
'Table'[Step] = "X"
),
CALCULATE (
MAX('Table'[Time]),
'Table'[Step] = "Z"
),
SECOND
),
"Z",
DATEDIFF (
CALCULATE (
MIN('Table'[Time]),
'Table'[Step] = "X"
),
CALCULATE (
MAX('Table'[Time]),
'Table'[Step] = "Z"
),
SECOND
)
)
),
[TimeDiff]
)
Yes, this works. I understood what i was missing. Thanks
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 53 | |
| 48 | |
| 35 | |
| 14 | |
| 14 |
| User | Count |
|---|---|
| 93 | |
| 79 | |
| 37 | |
| 27 | |
| 25 |