Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Dear Community
I have on my hands two formulas that allegedly represents Avg YTD:
1st:
avgYTDV1_Measure =
CALCULATE(AVERAGEX(VALUES('Date'[Monthnumber]),AVERAGE(OPS_ParetoTbl[MTBF])),
FILTER(ALL('Date'),
'Date'[Monthnumber] <= MAX('Date'[Monthnumber])
)
)
2nd:
Tot_Measure = AVERAGE(OPS_ParetoTbl[MTBF])
//---------------
AvgX_Measure = AVERAGEX(VALUES('Date'[MonthNameShort]),[Tot_Measure])
//--------------
avgYTDV2_Measure =
CALCULATE([MTBF_AvgX_Measure],
FILTER(ALL('Date'),
'Date'[Monthnumber] <= MAX('Date'[Monthnumber])
)
)
Result:
| Month | avgYTDV2_Measure | avgYTDV1_Measure | Monthly Avg |
| Jan | 10.21 | 10.21 | 10.21 |
| Feb | 17.97 | 18.53 | 25.73 |
| Mar | 22.29 | 22.29 | 30.94 |
| Apr | 24.99 | 25.16 | 33.09 |
| May | 30.85 | 29.69 | 54.25 |
while [avgYTDV2_Measure] is technically the correct one why is [avgYTDV1_Measure] isn't giving correct numbers??
Solved! Go to Solution.
Hi @Anonymous ,
You can get the answer from the following blog:
Caution When Using Variables in DAX and Power BI
You can also update the formula of measure [avgYTDV1_Measure] as below to get the correct result:
avgYTDV1_Measure =
VAR _avg =
CALCULATE ( AVERAGE ( OPS_ParetoTbl[MTBF] ) )
RETURN
CALCULATE (
AVERAGEX ( VALUES ( 'Date'[MonthNameShort] ), _avg ),
FILTER ( ALL ( 'Date' ), 'Date'[Monthnumber] <= MAX ( 'Date'[Monthnumber] ) )
)
Best Regards
Hi @Anonymous ,
You can get the answer from the following blog:
Caution When Using Variables in DAX and Power BI
You can also update the formula of measure [avgYTDV1_Measure] as below to get the correct result:
avgYTDV1_Measure =
VAR _avg =
CALCULATE ( AVERAGE ( OPS_ParetoTbl[MTBF] ) )
RETURN
CALCULATE (
AVERAGEX ( VALUES ( 'Date'[MonthNameShort] ), _avg ),
FILTER ( ALL ( 'Date' ), 'Date'[Monthnumber] <= MAX ( 'Date'[Monthnumber] ) )
)
Best Regards
@Anonymous , we should always use calculate in x functions , if we are not using a measure
avgYTDV1_Measure =
CALCULATE(AVERAGEX(VALUES('Date'[Monthnumber]),calculate(AVERAGE(OPS_ParetoTbl[MTBF]))),
FILTER(ALL('Date'),
'Date'[Monthnumber] <= MAX('Date'[Monthnumber])
)
)
@amitchandak Thank you for your prompt reply,
however, while calculate got me closer to the right answer its still not an exact YTD average
@Anonymous , the second one usages monthnameshort , please check if that can make a diff. Also can share what are you getting now with the formula's
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 44 | |
| 43 | |
| 38 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 68 | |
| 64 | |
| 31 | |
| 29 | |
| 24 |