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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hood2media
Resolver II
Resolver II

power query | replace value in 1 column based on content in another column - 1

hi,

following is a situation i'm in

1. i hv 2 columns called 'Category' & 'Item';

 

2. i have a situation where for each condition where Category-column contains "School Fees", each corresponding Item-column ietm is blank;

3. so, i need to replace each blanks in the Item-column with "School Fees"  for each cases where Category-column contains "School Fees";

 

4. lastly, i need for each cases where Category-column contains "School Fees", it will be replaced with "Fees"

 

5. finally, you won't have any blanks in the Item-column since they have been replaced with "School Fees" + for the Category column, there won't b "School Fees" anymore since it has also been replaced with "Fees".

i'd appreciate any help to write a power query for this.
tks & krgds, -nik

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi Nik ,

 

The first one you want to replace is [Item] as this depends on [Category] being "School Fees", so:

 

-1- Right-click on a null value in the [Item] column and select 'Replace Values...'. In the 'Replace With' box, type "School Fees". This will auto-generate code for you like this:

BA_Pete_1-1684240924034.png

 

-2- Adjust the highlighed section above so it looks like this instead:

BA_Pete_2-1684240977261.png

 

-3- Now you've done this bit, you can just right-click on a "School Fees" value in your [Category] column, select 'Replace Values...' again, and replace with "Fees".

 

Output:

BA_Pete_3-1684241050271.png

 

Full example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7OyM/PUXBLTS1W0lFSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Item = _t]),
    repBlankNull = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Item"}),

// Relevant steps from here ---->
    repItem = Table.ReplaceValue(repBlankNull, null, each if [Category] = "School Fees" then "School Fees" else null, Replacer.ReplaceValue,{"Item"}),
    repCategory = Table.ReplaceValue(repItem,"School Fees","Fees",Replacer.ReplaceText,{"Category"})

in
    repCategory

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
hood2media
Resolver II
Resolver II

many tks, @BA_Pete.

as there r also similar instances where Category = Donations & Items is blank, i have managed to use & modify that power query script you gave & correct the previous errors succesfully.

 

tks & krgds, -nik

 

 

BA_Pete
Super User
Super User

Hi Nik ,

 

The first one you want to replace is [Item] as this depends on [Category] being "School Fees", so:

 

-1- Right-click on a null value in the [Item] column and select 'Replace Values...'. In the 'Replace With' box, type "School Fees". This will auto-generate code for you like this:

BA_Pete_1-1684240924034.png

 

-2- Adjust the highlighed section above so it looks like this instead:

BA_Pete_2-1684240977261.png

 

-3- Now you've done this bit, you can just right-click on a "School Fees" value in your [Category] column, select 'Replace Values...' again, and replace with "Fees".

 

Output:

BA_Pete_3-1684241050271.png

 

Full example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7OyM/PUXBLTS1W0lFSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Item = _t]),
    repBlankNull = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Item"}),

// Relevant steps from here ---->
    repItem = Table.ReplaceValue(repBlankNull, null, each if [Category] = "School Fees" then "School Fees" else null, Replacer.ReplaceValue,{"Item"}),
    repCategory = Table.ReplaceValue(repItem,"School Fees","Fees",Replacer.ReplaceText,{"Category"})

in
    repCategory

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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.