Forum Discussion
ryan25r9
Helper I
6 years agoMeasure Efficiency -- Get distinct values, average per single date, then sum the averages
Hey everyone, I'm trying to find a way to refactor this measure to make it more efficient, since it's currently pretty slow. I've been spinning my wheels, so any help is greatly appreciated. ...
Ashish_Mathur
Super User
6 years agoryan25r9
Helper I
6 years agoGreatly appreciate the Power BI file, thanks so much. This actually returns the correct results, but running on the entire model drops the efficiency from 25 seconds to 171 seconds. The core table (TLG) is 700M rows, so that certainly isn't helping with the context transition. For reference, this is the old code simplified and your recommended code altered to run in DAX Studio:
EVALUATE
VAR Old =
SUMX(
GROUPBY(
SUMMARIZE(TLG, TLG[Date Worked], TLG[Employee ID], TLG[Workday Days])
, [Date Worked]
, "AvgWorkdays"
, AVERAGEX( CURRENTGROUP(), [Workday Days] )
)
, [AvgWorkdays]
)
VAR New =
SUMX (
VALUES ( 'TLG'[Date Worked] ),
AVERAGEX (
SUMMARIZE (
VALUES ( TLG[Employee ID] ),
[Employee ID],
"AvgWorkdays", CALCULATE(AVERAGE(TLG[Workday Days]))
),
[AvgWorkdays]
)
)
RETURN
ROW("test", New)