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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
IwanVB
Frequent Visitor

If statement based multiply without new column

I need one line of powerquery code for the following

- On a record, i have a field called "2024" (numeric)
- I have another field called "Currency" (text)
- If the Currency value is "EUR", then multiply the 2024 field by 2 in any other cast by 50.

 

Yes, this can be done by adding a new column and later remove the old ones, but looking for a solution without doing so.

Tried the code below but unfortunate not working: 

= Table.TransformColumns(#"PreviousStep", {{"2024", each if [Currency] = "EUR" then _ * 2 else _ * 50, type number}})



1 REPLY 1
lbendlin
Super User
Super User

You can also use Table.ReplaceValue.  Same basic idea,

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjVQ0lFyDQ1SitWJVjIHcUKDXZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"2024" = _t, Currency = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"2024", Int64.Type}, {"Currency", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [2024],each if [Currency]="EUR" then [2024]*2 else [2024]* 50,Replacer.ReplaceValue,{"2024"})
in
    #"Replaced Value"

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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