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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

replace nulls with last 3 months average

Hello Community,

 

Am looking for a power query that would help me replace the null values highlighted to the last 3 months average i.e.(July to Dec 2023 = (June,May,Apr)/3

 

MMB920_0-1686280085843.png

Would greatly appreciate your input to resolve.. thank you.

 

MMB

1 REPLY 1
m_dekorte
Super User
Super User

Hi @Anonymous,

 

Give this a go.

let
    Last3Months = Number.Round( List.Average( List.ReplaceMatchingItems( 
        Table.SelectRows( Source, each Date.IsInPreviousNMonths([month_], 2) or Date.IsInCurrentMonth([month_]) )[ib_call_pct], 
        {{null, 0}} )), 4 
    ),
    Source = Table.FromColumns(
        {
            List.Transform( {1..12}, each #date( 2023, _, 1) ),
            {.1655, null, .1442, .1506, .162, .0196, null, null, null, null, null, null}
        }, type table[ month_ = date, ib_call_pct = Percentage.Type]
    ),
    Replaced = Table.ReplaceValue( Source, each Record.ToList(_), each Record.ToList(_), (x, y, z)=> if (y{0} > Date.From( DateTime.FixedLocalNow()) and y{1} = null) then Last3Months else x, {"ib_call_pct"} )
in
    Replaced

 

with this result

m_dekorte_0-1686341069826.png

 

Ps. If this helps you solve your query, please mark it as solution. Thanks!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Kudoed Authors