Forum Discussion
This calculated column makes everything slow
I think what's happening is that every time you edit the model, it's recomputing the calculated column, which wasn't written especially efficiently. Defining this as a measure without using calculated columns should help and Greg_Deckler has another post about that here:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Mean-Time-Between-Failure-MTBF/m-p/625082
- AlexisOlson3 years ago
Super User
Note that Greg's measure will have similar performance issues (compared with the calculated column) but using it instead of a calculated column will keep you from needing to recalculate it each time you edit your model.
Using the new OFFSET function, here's a version that's about 30x faster (~6 ms vs ~180 ms) according to my testing against the pbix attached to the post I linked. It should be much better for large models as well as more dynamically adaptable to various filters (plus it only needs to calculate over all selected data rather than the entire fact table).
MTBF (Hours) AO = VAR _Summary_ = CALCULATETABLE ( SUMMARIZE ( Repairs, Repairs[MachineName], Repairs[RepairStarted], Repairs[RepairCompleted] ), KEEPFILTERS ( Repairs[RepairType] <> "PM" ) ) VAR _AddNext_ = ADDCOLUMNS ( _Summary_, "@NextRepair", SELECTCOLUMNS ( OFFSET ( 1, _Summary_, ORDERBY ( Repairs[RepairStarted] ), PARTITIONBY ( Repairs[MachineName] ) ), "RepairStarted", [RepairStarted] ) ) VAR _Uptime_ = ADDCOLUMNS ( _AddNext_, "@Uptime", DATEDIFF ( [RepairCompleted], COALESCE ( [@NextRepair], NOW () ), SECOND ) ) RETURN AVERAGEX ( _Uptime_, [@Uptime] ) / 3600- some1else3 years ago
Helper II
Wow, thanks for the extensive reply, I will look into it tonight.
Using the calculated column and the measure I get different results:Even the calculated column has some weird values. Look at the 5 and 6th rows, the MTBF should be 0, not 2283hours which is the MTBF between the 7 and 6th row. Any ideas?
- Greg_Deckler3 years ago
Community Champion
some1else It's going to be extremely difficult to troubleshoot this without some sample data as text and your measure formula.