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! Request now

Reply
Anonymous
Not applicable

Replace a value in a cell by a value in a cell above conditionally

Hi,

 

I am trying to replace a specific value in a cell with an other value in a cell above, but it only works for 1 cell.

For exampe, with the table :

 

col1 | col2

A | 17

B | 13

s | 14

s | 15

s | 28

C | 24

s | 32

 

What I want is to replace the three first letters "s" with the letter "B" and the last one with the letter "C". This is just an example and I can have more than only 4 "s" to replace.

 

In my Advanced Editor, I tried with a customed column :

#"Added Index" = Table.AddIndexColumn(#"Step 2", "Index", 0, 1, Int64.Type),
#"Added values above" = Table.AddColumn(#"Added Index", "Custom", each if [Col2] = "s" then #"Added Index"[Col2]{[Index] - 1} else [Col2])

 

But as I thought, it only replaces the first row with the "s", and the others don't change

 

If you can help me to do that, I would be greatful 🙂

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Is it what you want?

 

Vera_33_0-1626694489748.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclRQ0lEyNFeK1YlWcgKzjcHsYjDbBIltimAbWYDZzmA2khpjI6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t, col2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}, {"col2", Int64.Type}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","s ",null,Replacer.ReplaceValue,{"col1"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"col1"})
in
    #"Filled Down"

 

View solution in original post

1 REPLY 1
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Is it what you want?

 

Vera_33_0-1626694489748.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclRQ0lEyNFeK1YlWcgKzjcHsYjDbBIltimAbWYDZzmA2khpjI6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t, col2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}, {"col2", Int64.Type}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","s ",null,Replacer.ReplaceValue,{"col1"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"col1"})
in
    #"Filled Down"

 

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.