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

Circular error when replacing values in one column off another column

Hello. I am trying to simple replace values in one column off the values of another column  IF Dateofcall = 1/1/2019 then I want th evalue in the GMR_Agency to be "RR" so I wrote this:

 

=Table.ReplaceValue(#"Time-Agency", ---(this is the name of the query (table)- I guess I can call it anything?)
each [GMR_Agency] (this is the field where I want "RR" to be), each if [DateofCall] = "1/1/2019" (this is the VALUE I want to replace with RR in Dateofcall) then "RR" else [GMR_Agency],Replacer.ReplaceValue,{"GMR_Agency"})

 

I am getting the dreaded 'An error occurred in the ‘’ query. Expression.Error: A cyclic reference was encountered during evaluation.

Is the problem "TIME-AGENCY"?

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

It is worth noting that what is marked in red in the figure below is not the name of the query but the name of the applied step.

yingyinr_3-1634541842011.png

yingyinr_2-1634541819494.png

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Assume that you have the below table

yingyinr_1-1634540669737.png

2. Replace the value of column GMR_Agency with "RR" when the date of column DateofCall is equal to 2019/1/1 in Power Query Editor using Table.ReplaceValue function

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7DcAgDAXAXVwjGZuIJCX/ISz2XyMvpEBprzgzSokcCQurl5umM8r5FZBuKwV2scRNtYIOlgBSv6g10Pmj3kHhu1QWjQGKm+YD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [GMR_Agency = _t, DateofCall = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"GMR_Agency", type text}, {"DateofCall", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [GMR_Agency],each if [DateofCall] =#date(2019, 1, 1)  then "RR" else [GMR_Agency],Replacer.ReplaceValue,{"GMR_Agency"})
in
    #"Replaced Value"

yingyinr_0-1634541000810.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

It is worth noting that what is marked in red in the figure below is not the name of the query but the name of the applied step.

yingyinr_3-1634541842011.png

yingyinr_2-1634541819494.png

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Assume that you have the below table

yingyinr_1-1634540669737.png

2. Replace the value of column GMR_Agency with "RR" when the date of column DateofCall is equal to 2019/1/1 in Power Query Editor using Table.ReplaceValue function

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7DcAgDAXAXVwjGZuIJCX/ISz2XyMvpEBprzgzSokcCQurl5umM8r5FZBuKwV2scRNtYIOlgBSv6g10Pmj3kHhu1QWjQGKm+YD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [GMR_Agency = _t, DateofCall = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"GMR_Agency", type text}, {"DateofCall", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [GMR_Agency],each if [DateofCall] =#date(2019, 1, 1)  then "RR" else [GMR_Agency],Replacer.ReplaceValue,{"GMR_Agency"})
in
    #"Replaced Value"

yingyinr_0-1634541000810.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
AllisonKennedy
Super User
Super User

@Anonymous  As @xander2121  suggested you could try a new conditional column, so in Power Query click: Add Column tab in ribbon > Conditional column, then put your conditions in there rather than manual coding that is too easy to get errors. 

Then just delete the old column you don't need when you're done. 

 

Alternatively you may find this blog helpful for more advanced scenarios: https://www.howtoexcel.org/power-query/bulk-replace-values/  It's for Excel, but Power Query is the same in Excel and Power BI. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

xander2121
Frequent Visitor

Hello @Anonymous 

 

You can try to create a new column. I think Power BI won't let you replace values in a column.

 

Instead you create a new column with you conditions.

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.