Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

fill nulls with previous months averages

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:

MMB920_0-1685690042008.png

any thoughts on how to go around this problem?

 

Thank you,

M

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

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]))

vstephenmsft_0-1685945362257.png

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.           

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Anonymous ,

 

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]))

vstephenmsft_0-1685945362257.png

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.           

Anonymous
Not applicable

Hi @Anonymous ,

 

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

Anonymous
Not applicable

Hi @Anonymous ,

 

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.           

ppm1
Solution Sage
Solution Sage

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

Microsoft Employee
Anonymous
Not applicable

Hi Pat,

 

Appreciate putting the option. I would be interested to see a DAX solution, could you provide that?

 

Thanks,

M

AlienSx
Super User
Super User

<no dax>

Anonymous
Not applicable

Could we do a measure then?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.