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
Lenescarb
New Member

How to Separate a column into two by positive and negative numbers?

As the subject lines says I'm trying to use power query to create a new column that allows me to seperate amount totals by positive and negative.

 

For Example Im trying to go from this:

Lenescarb_0-1652707715589.png

 

To This: 

Lenescarb_1-1652707766269.png

 

1 ACCEPTED SOLUTION
rohit_singh
Solution Sage
Solution Sage

Hi @Lenescarb ,

Please try the following in Power Query. 

1) Load the data into PQ

rohit_singh_0-1652709704385.png

 

2) Split column "Amount" by delimiter "-". This will generatetwo columns "Amount.1" and "Amount.2"

rohit_singh_1-1652709758397.png

rohit_singh_2-1652709785647.png


3) Multiply column "Amount.2" by -1 to get negative values in the column

rohit_singh_3-1652709862895.png


Below are the steps :

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZA9D4IwGIT/SsOM0JavMlYo2ESpqVUj6EBMow5Agjror7dM6qIJ292by5N7r6qswEWeiyHGlm0h7PlBGJHY6KVkdK1mQvKSpYAmM5BIlnI1xILQiSMjkq451tebdbDHcSJMPIcMJKr2dwhxqMaySABtSIzY6P7y7FrwE1ROKUjZlCugJC1WGZPmOEHExjF04iEt+ro9aXA7665//GW9X/pAZMv57xZirXLBixwsRMF2X1V8FPrId6BnzNZMrEFTt/VJN7o1cx9e", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Post Date" = _t, #"Account Number " = _t, #"Transaction Description" = _t, Amount = _t, #"Transaction Detail" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Account Number ", Int64.Type}, {"Transaction Description", type text}, {"Amount", type number}, {"Transaction Detail", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type", {{"Amount", type text}}, "en-GB"), "Amount", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Amount.1", "Amount.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Amount.1", type number}, {"Amount.2", type number}}),
#"Multiplied Column" = Table.TransformColumns(#"Changed Type1", {{"Amount.2", each _ * -1, type number}})
in
#"Multiplied Column"



Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊



View solution in original post

1 REPLY 1
rohit_singh
Solution Sage
Solution Sage

Hi @Lenescarb ,

Please try the following in Power Query. 

1) Load the data into PQ

rohit_singh_0-1652709704385.png

 

2) Split column "Amount" by delimiter "-". This will generatetwo columns "Amount.1" and "Amount.2"

rohit_singh_1-1652709758397.png

rohit_singh_2-1652709785647.png


3) Multiply column "Amount.2" by -1 to get negative values in the column

rohit_singh_3-1652709862895.png


Below are the steps :

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZA9D4IwGIT/SsOM0JavMlYo2ESpqVUj6EBMow5Agjror7dM6qIJ292by5N7r6qswEWeiyHGlm0h7PlBGJHY6KVkdK1mQvKSpYAmM5BIlnI1xILQiSMjkq451tebdbDHcSJMPIcMJKr2dwhxqMaySABtSIzY6P7y7FrwE1ROKUjZlCugJC1WGZPmOEHExjF04iEt+ro9aXA7665//GW9X/pAZMv57xZirXLBixwsRMF2X1V8FPrId6BnzNZMrEFTt/VJN7o1cx9e", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Post Date" = _t, #"Account Number " = _t, #"Transaction Description" = _t, Amount = _t, #"Transaction Detail" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Account Number ", Int64.Type}, {"Transaction Description", type text}, {"Amount", type number}, {"Transaction Detail", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type", {{"Amount", type text}}, "en-GB"), "Amount", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Amount.1", "Amount.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Amount.1", type number}, {"Amount.2", type number}}),
#"Multiplied Column" = Table.TransformColumns(#"Changed Type1", {{"Amount.2", each _ * -1, type number}})
in
#"Multiplied Column"



Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊



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