Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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:
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
Solved! Go to Solution.
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
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
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 50 | |
| 44 | |
| 42 | |
| 19 | |
| 19 |
| User | Count |
|---|---|
| 69 | |
| 68 | |
| 33 | |
| 32 | |
| 32 |