We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Is there a way to add a second columns criteria to a SWITCH function?
In short, I would like to make a calculation if the STORE # = one of a list OR if the beginning of the Coupon = a certain phrase. The data is in the same table, but different columns.
I started with this to calculate based on the store number only. Now I need to add the coupon name.
Calculation = CALCULATE((SUM('sales_order'[discount_amount])*-1)*.5,SWITCH('sales_order'[store_id],8,TRUE(),37,TRUE(),38,TRUE(),39,TRUE(),44,TRUE(),0))
So in excel I would do something like this to find the beginnging text in the coupon. Unforunately I don't know how to add it to DAX as a condition or even if that is the right way.
IFERROR(TRIM(LEFT('sales_order'[coupon],FIND("-",'sales_order'[coupon])-1))="COUPON TEXT",0)))
(I know there may be other ways, but hopefully you get the idea)
Solved! Go to Solution.
In SWITCH() function, we can only put single column to apply condition. Since you need another column for applying condition, you have to use nested IF() to achieve your goal.
Regards,
with the switch statement you can use a test for TRUE() as your evaluation criteria; eg: calc=switch(true(), blah=blah && foo=bar, 1, bar=blah || foo=foo, 2, 3)
Proud to be a Super User!
The function OR() can be used with the SWITCH() Function like that : OR(<logical1>,<logical2>)
In SWITCH() function, we can only put single column to apply condition. Since you need another column for applying condition, you have to use nested IF() to achieve your goal.
Regards,
with the switch statement you can use a test for TRUE() as your evaluation criteria; eg: calc=switch(true(), blah=blah && foo=bar, 1, bar=blah || foo=foo, 2, 3)
Proud to be a Super User!
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 |
|---|---|
| 54 | |
| 39 | |
| 34 | |
| 18 | |
| 18 |
| User | Count |
|---|---|
| 69 | |
| 64 | |
| 38 | |
| 34 | |
| 23 |