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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lhern_ndez
Helper I
Helper I

Calculated column with LEFT function and multiple IF depending in other Column conditions

Hello,

 

I have several columns in a table and I need to create a calculated column which value will depend on the first number of one of the column's value, see extract of the table:

 

 

Data_IF.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Basically it is transactions and I want to personalize the positive or negative sign for reporting purposes.

 

I would need that the new column: REPORTING AMOUNT multiplies the AMOUNT values by -1 or +1 depending on the first number of the column Account Number. For instance, If the Account Number starts with 1 or 4 then the Amount value should be multiplied by -1 in the case that the Account Number starts with 2,3, or 5, then the AMOUNT should be multiplied by +1.

 

 

Thanks in advance for the help!

 

Luis

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @lhern_ndez

 

Try this, this will work.

 

New_Col = SWITCH(TRUE(),
                 LEFT(Table1[AcctNo],1) in {"0","1","2","3"},Table1[Amt]*-1,
                 LEFT(Table1[AcctNo],1) in {"4","5","6"},Table1[AcctNo]*1
)

 

 

Thanks
Raj

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @lhern_ndez

 

Try this, this will work.

 

New_Col = SWITCH(TRUE(),
                 LEFT(Table1[AcctNo],1) in {"0","1","2","3"},Table1[Amt]*-1,
                 LEFT(Table1[AcctNo],1) in {"4","5","6"},Table1[AcctNo]*1
)

 

 

Thanks
Raj

Anonymous
Not applicable

Hi

SWITCH is also internally performing the IF function only. The above SWITCH is equivalent to the below nested IF statement.

 

New_Col=

IF ( LEFT(Table1[AcctNo],1) in {"0","1","2","3"},Table1[Amt]*-1,IF(LEFT(Table1[AcctNo],1) in {"4","5","6"},Table1[AcctNo]*1))

 

More on SWITCH :

https://msdn.microsoft.com/en-us/query-bi/dax/switch-function-dax

 

Hope this helps you.

 

Thanks

Raj

Great, thanks!

Thanks Rajendran,

 

It does what needed!

 

Could you please briefly explain the formula?

I do not understand the interaction of Switch with True and then the relation with IN....

 

Thanks!

 

Luis

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.