The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hello. I want to make a minus sign in front of a value in a column that corresponds to a text value in another column. Shown under I want make a "-" sign in front of all the numbers in lots when buy or sell is sell?
Like this:
Buy | 2 |
Sell | -1 |
Sell | -3 |
Buy | 2 |
Sell | -1 |
Solved! Go to Solution.
Hi @LFM, add as custom column:
if Text.Lower([Buy or Sell]) = "sell" then [Lots] * -1 else [Lots]
Whole code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnb18VHSUTJUitWJVnIKjQSyjcBsqIQpMscYSZUJEtsQWRFQeywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Buy or Sell" = _t, Lots = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"Lots", type number}}),
#"Ad_Lots +/-" = Table.AddColumn(ChangedType, "Lots +/-", each if Text.Lower([Buy or Sell]) = "sell" then [Lots] * -1 else [Lots], type number)
in
#"Ad_Lots +/-"
Hi @LFM, add as custom column:
if Text.Lower([Buy or Sell]) = "sell" then [Lots] * -1 else [Lots]
Whole code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnb18VHSUTJUitWJVnIKjQSyjcBsqIQpMscYSZUJEtsQWRFQeywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Buy or Sell" = _t, Lots = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"Lots", type number}}),
#"Ad_Lots +/-" = Table.AddColumn(ChangedType, "Lots +/-", each if Text.Lower([Buy or Sell]) = "sell" then [Lots] * -1 else [Lots], type number)
in
#"Ad_Lots +/-"