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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
LFM
Helper III
Helper III

Minus sign in front of a value that corresponds to a certain text

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?

LFM_0-1721400637958.png

Like this:

Buy2
Sell-1
Sell-3
Buy2
Sell-1
1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @LFM, add as custom column:

 

if Text.Lower([Buy or Sell]) = "sell" then [Lots] * -1 else [Lots]

dufoq3_0-1721402515333.png

 

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 +/-"

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

1 REPLY 1
dufoq3
Super User
Super User

Hi @LFM, add as custom column:

 

if Text.Lower([Buy or Sell]) = "sell" then [Lots] * -1 else [Lots]

dufoq3_0-1721402515333.png

 

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 +/-"

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors