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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
TimTeska
Frequent Visitor

How to change the value of one field in a column

Hello Experts,

I want to be able to change the value of row 6 in [Custom] column to say "Period".  The reason for this is because the next steps I make will be to 1) remove the top 5 rows and then 2) "Use First Row As Headers".

The reason why it's important to change the value on row five to "Period" so the column header becomes "Period" is because this data gets refreshed by replacing the source Excel file with the next quarter.  So if I simply just remove the top 5 rows, and then "Use First Row As Headers" and change the column name from "2023_Close_Q2...." to "Period" I get an error when I  replace the source Excel file with the next quarter and refresh with Q3's data because it's looking for "2023_Close_Q2...." as the column name to change it to "Period".

**The [Custom] column is created using the value from [Column1]{3}, Therefore, this value changes with every new quarter that the source data report is run.  see below.

Any help would be great appreciated - Thank you!!

pbi problem.png

1 ACCEPTED SOLUTION
TimTeska
Frequent Visitor

I found the answer from another post.

Create a conditional column that would look at the column next to [Custom] for a header value (in this case it was "Effective Tax Rate", if so ="Period" otherwise [Custom]..    

View solution in original post

2 REPLIES 2
collinsg
Super User
Super User

Good day TimTeska,

Below I have pasted a custom function which takes a table and replaces the value in a given record and column. In your script you could add the step 

= fn(#"Added Custom",5,"Custom","Period") 

This would replace the value in row 6 and column "Custom" with the value "Period". (Row 6 is record 5 because records are indexed from zero). To use the function copy the code below and paste it into Power Query as a query. Name the query "fn" and then add the line above to your script.

Hope this helps

 

(tbl as table, recordIndex as number, columnName as text, newValue as text) as table =>
let
    replaceRecord = Table.ReplaceRows(
        tbl,
        recordIndex,
        1,
        {
            Record.FromList(
                List.ReplaceRange(
                    Record.ToList(tbl{recordIndex}),
                    List.PositionOf(Table.ColumnNames(tbl), columnName),
                    1,
                    {newValue}
                ),
                Table.ColumnNames(tbl)
            )
        }
    )
in
    replaceRecord

 

TimTeska
Frequent Visitor

I found the answer from another post.

Create a conditional column that would look at the column next to [Custom] for a header value (in this case it was "Effective Tax Rate", if so ="Period" otherwise [Custom]..    

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors