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 the first value of a specific column.

I have a column named Reports. How can I replace only the first value in this column with "bananas" for example?

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Anonymous , Use below m code for this

let
Source = ... , // Your data source here
AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
ReplaceFirstValue = Table.AddColumn(AddIndex, "Updated Reports", each if [Index] = 0 then "bananas" else [Reports]),
RemoveIndex = Table.RemoveColumns(ReplaceFirstValue,{"Index"}),
FinalTable = Table.RemoveColumns(RemoveIndex,{"Reports"}),
RenamedTable = Table.RenameColumns(FinalTable,{{"Updated Reports", "Reports"}})
in
RenamedTable

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

6 REPLIES 6
AlienSx
Super User
Super User

Table.ReplaceRows(Source, 0, 1, {Table.First(Source) & [Reports = "banana"]})
p45cal
Super User
Super User

Look at the ReplacedValue step.

p45cal_0-1724622811951.png

Put the code below into a blank Advanced Editor.

 

let
    Source = Table.ExpandRecordColumn(Table.FromList(Json.Document(Binary.FromText( "W3siSGRyMSI6InN0dWZmIiwiUmVwb3J0cyI6Im9uZSIsIkhkcjMiOiJzdHVmZiJ9LHsiSGRyMSI6InN0dWZmIiwiUmVwb3J0cyI6InR3byIsIkhkcjMiOiJzdHVmZiJ9LHsiSGRyMSI6InN0dWZmIiwiUmVwb3J0cyI6InRocmVlIiwiSGRyMyI6InN0dWZmIn0seyJIZHIxIjoic3R1ZmYiLCJSZXBvcnRzIjoiZm91ciIsIkhkcjMiOiJzdHVmZiJ9LHsiSGRyMSI6InN0dWZmIiwiUmVwb3J0cyI6ImZ2ZSIsIkhkcjMiOiJzdHVmZiJ9XQ==",BinaryEncoding.Base64),1252), Splitter.SplitByNothing()), "Column1", {"Hdr1", "Reports", "Hdr3"}),
    AddedIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    ReplacedValue = Table.ReplaceValue(AddedIndex,each [Reports],each if [Index] = 0 then "banana" else [Reports],Replacer.ReplaceValue  ,{"Reports"}),
    RemovedColumns = Table.RemoveColumns(ReplacedValue,{"Index"})
in
    RemovedColumns

 

 

 

ronrsnfld
Super User
Super User

Try this:

let
    Source = Table.FromRecords(
        {[Column1 = "A"],
        [Column1 = "B"],
        [Column1 = "C"]},
        type table [Column1=text]),
    
    Banana = Table.FromColumns(
        {{"Banana"} & List.RemoveFirstN(Source[Column1])},
        type table[Column1=text])
in
    Banana
Omid_Motamedise
Super User
Super User

See this small example 

let
Source = Table.FromRecords({
[Reports = 1],
[Reports = 2],
[Reports = 3]
}),
Custom1 = Table.FromRecords({Source{0} & [Reports="Banana"]}) & Table.RemoveFirstN(Source,1)
in
Custom1


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

@Anonymous , Use below m code for this

let
Source = ... , // Your data source here
AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
ReplaceFirstValue = Table.AddColumn(AddIndex, "Updated Reports", each if [Index] = 0 then "bananas" else [Reports]),
RemoveIndex = Table.RemoveColumns(ReplaceFirstValue,{"Index"}),
FinalTable = Table.RemoveColumns(RemoveIndex,{"Reports"}),
RenamedTable = Table.RenameColumns(FinalTable,{{"Updated Reports", "Reports"}})
in
RenamedTable

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Anonymous
Not applicable

I tried using this:
ReplaceLineValue = Table.TransformColumns( AddIndex, {{"Line", each if [Index] = 0 or List.Contains(List.Transform(MachineNamePositions, each _ + 2), [Index]) then "Line" else _}})
I want to replace when the Index is 0 and when the index is equal to machineNamePositions plus 2 rows. Machine name positions is a list of indexes.
MachineNamePositions = Table.SelectRows(AddIndex, each [Column1] = "Machine")[Index]

But this didnt replace the values.

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.