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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors