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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
neonguyen1803
Frequent Visitor

Replace null with median

Dear all,

 

I have the data below: 

 

neonguyen1803_0-1698082436815.png

I want to replace the value null in column Week 1-2-3-4 with Median Column for each row --> it's mean for row 5, null value in Week 2 will be replaced to 8 (based on Median Column value in row 5 is 8 )

 

Thanks

 

2 ACCEPTED SOLUTIONS
AlienSx
Super User
Super User

Hello, @neonguyen1803 if your table has nulls only in columns Week 1..4 then 

let
    Source = your_table,
    lst = Table.FromList(
            Table.ToList(
                Source, (x) => List.ReplaceValue(x, null, List.Last(x), Replacer.ReplaceValue)
            ), (x) => x, Table.ColumnNames(Source)
    )
in
    lst

View solution in original post

ronrsnfld
Super User
Super User

You can do this using the Table.ReplaceValue function with appropriate arguments to look at the Median column for the replacement value.

 

If your values might include decimals, be sure to set the data types to number rather than Int64.Type.

 

 

#"Replace Columns" = List.Select(Table.ColumnNames(#"Previous Step"), each Text.StartsWith(_,"Week")),
    #"Replace Nulls with Median" = Table.ReplaceValue(#"Previous Step",
        null,
        each [Median],
        Replacer.ReplaceValue,
        #"Replace Columns"),
    #"Reset Data Types" = Table.TransformColumnTypes(#"Replace Nulls with Median", List.Transform(#"Replace Columns", each {_, type number}))
in
    #"Reset Data Types"

 

 

View solution in original post

2 REPLIES 2
ronrsnfld
Super User
Super User

You can do this using the Table.ReplaceValue function with appropriate arguments to look at the Median column for the replacement value.

 

If your values might include decimals, be sure to set the data types to number rather than Int64.Type.

 

 

#"Replace Columns" = List.Select(Table.ColumnNames(#"Previous Step"), each Text.StartsWith(_,"Week")),
    #"Replace Nulls with Median" = Table.ReplaceValue(#"Previous Step",
        null,
        each [Median],
        Replacer.ReplaceValue,
        #"Replace Columns"),
    #"Reset Data Types" = Table.TransformColumnTypes(#"Replace Nulls with Median", List.Transform(#"Replace Columns", each {_, type number}))
in
    #"Reset Data Types"

 

 

AlienSx
Super User
Super User

Hello, @neonguyen1803 if your table has nulls only in columns Week 1..4 then 

let
    Source = your_table,
    lst = Table.FromList(
            Table.ToList(
                Source, (x) => List.ReplaceValue(x, null, List.Last(x), Replacer.ReplaceValue)
            ), (x) => x, Table.ColumnNames(Source)
    )
in
    lst

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors