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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Frequent Visitor

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



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



Super User
Super User

Hi @MMB920,


Give this a go.

    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"} )


with this result



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

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors