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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Replace Value on a filtered column in Power BI

I want to replace value from 1 July 2018 to 30 June 2018 which works great but I want to replace only where Trx_Desc = 'Beginning Balance'. I was wondering how to add that to my M code?

 

let
Source = Sql.Database("abcd", "def"),
relational_COA_Transactions = Source{[Schema="relational",Item="COA_Transactions"]}[Data],
#"Replaced Value" = Table.ReplaceValue(relational_COA_Transactions,#datetime(2018, 7, 1, 0, 0, 0),#datetime(2018, 6, 30, 0, 0, 0),Replacer.ReplaceValue,{"Trx_Date"})
in
#"Replaced Value"

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @Anonymous ,

Please provide some dummy data with similar structure as table formula, it is hard to modify your formula without any detail sample data.

How to Get Your Question Answered Quickly 

BTW, why not consider to add a custom column to use if statement to replace record values, it should more simply than coding formula in 'replace value' functions.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Table is called COA_Transactions. I want to replace values of Date field using m code. I want to replace 1/7/2019 with 6/30/2019 but only where TRX_Desc = Beginning Balance. Rest I want to leave as is.

Sample Data:

DateCOA_AmountTrx_Desc
1/7/20191900Beginning Balance
1/7/2019247Beginning Balance
1/7/20191284Food Expense
1/8/2019198Asset Purchase
1/9/2019198Asset Purchase
1/10/2019198Asset Purchase
1/11/201950Asset Purchase
1/12/2019256Asset Purchase
1/13/2019198Asset Purchase
Anonymous
Not applicable

HI @Anonymous ,

You can use the following code to replace your replace value step:

#"Replaced Value" = Table.ReplaceValue(relational_COA_Transactions,each [Trx_Date],each if [Trx_Date]= #date(2019, 1, 7) and [Trx_Desc]="Beginning Balance" then #date(2019, 6, 30) else [Trx_Date],Replacer.ReplaceValue,{"Trx_Date"})

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.