Forum Discussion
DAX Measure Optimization - Please help
- 7 months ago
Hi Sir, Thank you for your reply! There is indeed a relationship between DimKPI and FactProductivity via key "KPIKey". However, when I use the version that you suggested I received the following error "A single value for column 'KPIKey' in table 'DimKPI' cannot be determined. This can happen when a measure or function formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."
This is fine though, I will use the TRETAS measure that you confirmed is definitely the best alternative to the original measure. Thanks a lot again!
Hi NRF95,
I hope you are doing well today ☺️❤️
So both Solutions A and B return correct results but from a performance and best practice DAX POV ,Solution B is strongest and more optimized approach
Let me Explain it for you
First Approach (A Solution)
- While A is a Good approach but it still introduces unnecessary overhead Like:
It relies on a CALCULATE inside SUMX which causes repeated context transitions (Not ideal for Performance)
The KPI filter is applied outside the iterator meaning it will reevaluate for each row group
In short it will produce more Formula Engine work than needed
Second Approach (B Solution) - Better Solution
This Solution improves performance in several important ways like:
The KPI filter is pushed inside SUMMARIZECOLUMNS allowing it to be applied once and early
It avoids nested CALCULATE calls inside iterators
SUMMARIZECOLUMNS is well optimized by the engine (for grouping and measure evaluation)
This is best for reducing context transitions and improves Engine efficiency
- In Short Approach B is both cleaner and faster while doing the exact calculation logic
Final Recommendation:
- Do this if there is a relationship between DimKPI and FactProductivity this final version is more clean and well performed:
CY Periodical - OMNI - # Actual Covering Agents =
VAR _KPIKey = 271
RETURN
SUMX(
SUMMARIZECOLUMNS(
FactProductivity[FiscalMonth],
FactProductivity[CustomerKey],
KEEPFILTERS ( DimKPI[KPIKey] = _KPIKey ),
"Covered",
[CY Periodical Generic - Productivity - DCount LastEmployeeKey]
),
[Covered]
)- If there is no relationship between them then Solution B using TREATAS is the correct and optimized
Hi Sir, Thank you for your reply! There is indeed a relationship between DimKPI and FactProductivity via key "KPIKey". However, when I use the version that you suggested I received the following error "A single value for column 'KPIKey' in table 'DimKPI' cannot be determined. This can happen when a measure or function formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."
This is fine though, I will use the TRETAS measure that you confirmed is definitely the best alternative to the original measure. Thanks a lot again!
- Ahmed-Elfeel7 months agoSuper User
Hi NRF95,
if my reply helps, then I would appreciate mark it as the solution to help the other members find it more quickly.