Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello community,
I have a problem where I want to fill future months (nulls) with the last 3 months averagrs.
here is a screenshot of my editor page for illustration:
any thoughts on how to go around this problem?
Thank you,
M
Solved! Go to Solution.
Hi @MMB920 ,
Here's an example for the measure fill nulls with previous months average:
Measure = var _maxdate=MAXX(FILTER(ALLSELECTED('Table'),[Value]<>BLANK()),[Date])
var _start=EOMONTH(_maxdate,-3)
var _end=EOMONTH(_maxdate,0)
return IF(SUM('Table'[Value])=BLANK(),DIVIDE(CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Date]>_start&&[Date]<=_end)),3),SUM('Table'[Value]))
The measure is calculated based on the maximum date in the 'Table' where the 'Value' column is not blank. The formula then calculates the start and end dates of a 3-month period ending with the maximum date. If the sum of the 'Value' column is blank, the formula calculates the average of the 'Value' column for the 3-month period. Otherwise, the formula returns the sum of the 'Value' column.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @MMB920 ,
Here's an example for the measure fill nulls with previous months average:
Measure = var _maxdate=MAXX(FILTER(ALLSELECTED('Table'),[Value]<>BLANK()),[Date])
var _start=EOMONTH(_maxdate,-3)
var _end=EOMONTH(_maxdate,0)
return IF(SUM('Table'[Value])=BLANK(),DIVIDE(CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Date]>_start&&[Date]<=_end)),3),SUM('Table'[Value]))
The measure is calculated based on the maximum date in the 'Table' where the 'Value' column is not blank. The formula then calculates the start and end dates of a 3-month period ending with the maximum date. If the sum of the 'Value' column is blank, the formula calculates the average of the 'Value' column for the 3-month period. Otherwise, the formula returns the sum of the 'Value' column.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-stephen-msft ,
Much appreciate your help here this actually worked.
One last step to make it perfect, I applied an IF statement to replace for values coming up as NULLs (future ones) while keeping actual as is.
My formula went as the following; avg_forecast = if([Measure_actual] = NULL, [Measure], [Measure_Actual]).
I was encountered with error stating 'NULL' is not supported in this context. Any input/suggestion to this?
Thank you,
MMB
Hi @MMB920 ,
Try using BLANK() instead of NULL.
avg_forecast = if([Measure_actual] = BLANK() , [Measure], [Measure_Actual]).
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
What do you plan to do with these columns once generated? Why not just calculate it with a measure so it is responsive to slicers and doesn't take up memory and/or increase refresh time?
Pat
Hi Pat,
Appreciate putting the option. I would be interested to see a DAX solution, could you provide that?
Thanks,
M
<no dax>
Could we do a measure then?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.