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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
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
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.