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

Change column numerical value based on text value of another column

Hello,

I have the following table loaded in Power Query and i am trying to change the sign in the "Amount" column to negative if the value in the "Saving" column is "No", otherwise the Amount value stays unchanged/positive. Any help is much appreciated!

 

DateSavingAmount
04/08/2022Yes2439.17
04/08/2022No1176.56
01/08/2022Yes791024.45
15/07/2022Yes11810.25
20/07/2022No12352.03
15/07/2022Yes81045.86
05/07/2022No365.95
05/07/2022No4509.88
15/07/2022Yes52011
06/07/2022Yes2922.4
15/07/2022No9592.56
15/07/2022Yes32471.67
15/07/2022Yes6793.62
15/07/2022No33938.1
15/07/2022Yes4390
15/07/2022No135385
15/07/2022Yes104310
04/07/2022Yes4598.01
14/07/2022Yes78597

 

Expected results:

DateSavingAmount
04/08/2022Yes2439.17
04/08/2022No-1176.56
01/08/2022Yes791024.45
15/07/2022Yes11810.25
20/07/2022No-12352.03
15/07/2022Yes81045.86
05/07/2022No-365.95
05/07/2022No-4509.88
15/07/2022Yes52011
06/07/2022Yes2922.4
15/07/2022No-9592.56
15/07/2022Yes32471.67
15/07/2022Yes6793.62
15/07/2022No-33938.1
15/07/2022Yes4390
15/07/2022No-135385
15/07/2022Yes104310
04/07/2022Yes4598.01
14/07/2022Yes78597

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZG7DsIwDEX/JXPl+pnYP8GOqo7MDPy/RNQAggYvXo7PtZK7bQV1RV8ZmctSrrdHn6wSQK3sywlf7n0QtQpWB6VJbkHICmrHAtmK7XeByAmBB2f84iOexRhQMr3LauCv+3bWpRqEJVANA9yzaGMkGmqdIAcz6KwewWHB7z/5EyysjaC2jNcWApWTcJEQB8rkXhYmJomJ50WgCuGn5XOshQO+rs64uUV/z/4E", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Saving = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Saving", type text}, {"Amount", type number}},"en-GB"),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type", each [Amount], each if [Saving] = "Yes" then -[Amount] else [Amount], Replacer.ReplaceValue, {"Amount"})
in
    #"Replaced Value"

CNENFRNL_0-1659900923770.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZG7DsIwDEX/JXPl+pnYP8GOqo7MDPy/RNQAggYvXo7PtZK7bQV1RV8ZmctSrrdHn6wSQK3sywlf7n0QtQpWB6VJbkHICmrHAtmK7XeByAmBB2f84iOexRhQMr3LauCv+3bWpRqEJVANA9yzaGMkGmqdIAcz6KwewWHB7z/5EyysjaC2jNcWApWTcJEQB8rkXhYmJomJ50WgCuGn5XOshQO+rs64uUV/z/4E", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Saving = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Saving", type text}, {"Amount", type number}},"en-GB"),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type", each [Amount], each if [Saving] = "Yes" then -[Amount] else [Amount], Replacer.ReplaceValue, {"Amount"})
in
    #"Replaced Value"

CNENFRNL_0-1659900923770.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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.

Top Solution Authors
Top Kudoed Authors