I’ve run into a similar problem, except I was trying to filter based on a relationship table and anything past four layers wouldn’t work. There is a limit to how much can be calculated in a single measure or table, and what helped me was using a CALCULATE function to filter the measure to precisely what I wanted it to look at. Wrapping your entire equation into a CALCULATE function with filter contexts of the transactions times might help.
I did a quick mock-up in DAX Studio. The second one shows it in a calculate function, so now we need to decide how we want to filter the transaction times. It’s possible the second equation by itself will help, but the syntax probably won’t work.
You could put them into filter functions to make sure it doesn’t go back too far, or you could use the KEEPFILTERS function to try and limit what the measure is trying to calculate. Here’s an article on that function and how it works within a CALCULATE function:
Transaction Duration BEFORE (sec) =
SUMX (
bm_Transactions,
DATEDIFF (
bm_Transactions[Transaction Start Time],
bm_Transactions[Transaction End Time],
SECOND
)
)
Transaction Duration AFTER (sec) =
CALCULATE (
SUMX (
bm_Transactions,
DATEDIFF (
bm_Transactions[Transaction Start Time],
bm_Transactions[Transaction End Time],
SECOND
)
), bm_Transactions[Transaction Start Time], bm_Transactions[Transaction End Time]
)
The name of the game here is to use the CALCULATE function and it’s conditions to make the measure calculate as little information as possible.
Dang. The only thing I can think of is to add a KEEPFILTERS argument for the year in case it’s calculating other years in the background.
Otherwise, you may have to settle on a rolling 4 months for seconds.
Something else I just thought of is to try calculating with minutes and converting it to seconds. Hopefully, the calculation load will be reduced enough for a full year.
I currently have rolling quarters as a temporary work around.
I actually have a DATEDIFF with DAYS granularity, but it returns an INT and rounds off the seconds, so I can convert it back. I haven’t tried minutes yet, let me try that now.
Edit: Yeah, same issue with DATEDIFF by MINUTE granularity, it truncates the seconds and returns an INT. Which removes the ability to convert back to seconds.
And, I definitely can’t settle for it because a ton of transactions with durations under 60 seconds become 0 minutes as the image below shows:
I’m not entirely sure, it’s a little hard without a file to work with. I was thinking you might be able to wrap the output in the original equation in a CONVERT function to override it turning it into an integer. You’re unfortunately pushing the boundaries of DAX’s ability to compute at the moment.
An interesting breakthrough! I’ll brush on DAX optimization methods - we’re probably running into issues with the internal formula engine as it can only run on a single core. Let’s also see if you’re able to mask the PBI file to share.
I find it fascinating working on issues like these where you’re pushing the absolute boundaries of what PBI can do.
Update: If you’re able to split your transaction date column into a date column and a time column (without a calculated column, so in your query) that has a lot of potential for optimization.