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! Learn more

Reply
lcmbany
New Member

How to replace some NULL values by text values from another column in the same rows

Hello

In the case of two columns, one "Product Name" containing non-zero values and the other "Category Name" containing 70% of values named "null", example on 5 lines: "Product Name" line 1 = Levi's 501 jeans, "Category Name" line 1 = Apparel; "Product Name" line 2 = Toyota Corolla, "Category Name" line 2 = Automotive; "Product Name" line 3 = iPhone 12, "Category Name" line 3 = Electronics; "Product Name" line 4 = Chevrolet Cruze, "Category Name" line 4 = null; "Product Name" line 5 = iPhone 14, "Category Name" line 5 = null,
How do I replace all null values with the non-null values in the Product Name column in the same row as the null values in the Category Name column?

5 REPLIES 5
Omid_Motamedise
Super User
Super User

You can also use this formula

let
Source = Table.FromRows({
{"Levi's 501 jeans", "Apparel"},
{"Toyota Corolla", "Automotive"},
{"iPhone 12", "Electronics"},
{"Chevrolet Cruze", null},
{"iPhone 14", null}
}
),
Replaced = Table.ReplaceValue(Source,null,each _[Column1],(a,b,c)=>a??c,{"Column2"})
in
Replaced


If my answer helped solve your issue, please consider marking it as the accepted solution.

Hello Omid,
Maybe I wasn't clear. Let me tell you what I need :

IDProduct NameCategory NameCustomer Name
1Pepsi ColaBeveragesYannick
2Honda CivicAutomotiveOliver
3Zara clothingApparelKurt
4Rolex watchesAccessories/JewelryJoel
5Bose headphonesElectronicsIsabelle
6Levi's 501 jeansnullEmerode
7Toyota CorollanullNoah
8Pepsi ColanullAlbert
9PlayStation 5nullSisca
10Honda CivicnullJessy
11Starbucks CoffeenullMetthew

I need for each "null" value takes a valid and good category name.

How to do this?

For example :

Row 1 Pepsi Cola = Berevages. But for the same product at the Row 8 = null?

Row 2 Honda Civic = Automobile. But at the Row 7, Toyota Corolla = null?

Row 9, we know that the PlayStation 5 element is on the Electronics category, same as Bose headphones. But on this row, we see null.

I'm wondering how to make sure that each "null" value is replaced with the correct category of each product in the "null" row?

Use this formula, Source is your table

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Product Name"}, {{"Count", each Table.FillUp(Table.FillDown(_,{"Category Name"}),{"Category Name"})}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"ID", "Category Name", "Customer Name"}, {"ID", "Category Name", "Customer Name"})
in
#"Expanded Count"


If my answer helped solve your issue, please consider marking it as the accepted solution.
OwenAuger
Super User
Super User

Hi @lcmbany 

If I've understood correctly, you want to replace each null Category Name value with the Product Name value in the same row.

 

Here's an example:

 

let
  Source = #table(
    type table [Product Name = text, Category Name = text],
    {
      {"Levi's 501 jeans", "Apparel"},
      {"Toyota Corolla", "Automotive"},
      {"iPhone 12", "Electronics"},
      {"Chevrolet Cruze", null},
      {"iPhone 14", null}
    }
  ),
  #"Replace null Category Names" = Table.ReplaceValue(
    Source,
    null,
    (_) as text => [Product Name],
    Replacer.ReplaceValue,
    {"Category Name"}
  )
in
  #"Replace null Category Names"

 

Does this work as expected?

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Hi @OwenAuger 

Sorry for my silent, was very busy at work!

I tried your code, but got result error.

Same as my firt answer to @Omid_Motamedise, maybe I wasn't clear. Let me tell you what I need :

IDProduct NameCategory NameCustomer Name
1Pepsi ColaBeveragesYannick
2Honda CivicAutomotiveOliver
3Zara clothingApparelKurt
4Rolex watchesAccessories/JewelryJoel
5Bose headphonesElectronicsIsabelle
6Levi's 501 jeansnullEmerode
7Toyota CorollanullNoah
8Pepsi ColanullAlbert
9PlayStation 5nullSisca
10Honda CivicnullJessy
11Starbucks CoffeenullMetthew

I need for each "null" value takes a valid and good category name.

How to do this?

For example :

Row 1 Pepsi Cola = Berevages. But for the same product at the Row 8 = null?

Row 2 Honda Civic = Automobile. But at the Row 7, Toyota Corolla = null?

Row 9, we know that the PlayStation 5 element is on the Electronics category, same as Bose headphones. But on this row, we see null.

I'm wondering how to make sure that each "null" value is replaced with the correct category of each product in the "null" row?

Helpful resources

Announcements
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!

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.