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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
donnellyk
Frequent Visitor

DAX Case to output either Column A or Column B

Very new to DAX & expect this is quite simple

I have some currency columns in my data set that have base currency values & local currency
e.g
Haulage
Haulage_Base
TotalCost
TotalCost_base
etc

I want to create a Custom column that outputs either the local currency or base currency value based on an idSite in a related table

How I'd do this in SQL would be; 

Case if othertable.idSite in (0,1,5) then haulage_base else haluage END as CustomHaulage

I've been successfully able to pull in the vaue of the idSite from the other table to a new custom column with

Site = RELATED(othertable[idSite])

So, I thought I could us CASE as below to create my new column

CustomHaulage = (Case when RELATED(othertable[idSite] in (0,1,5) then haulage_base else haulage END)

But I just get a column full of errors & "The syntax for 'Case' is incorrect. (DAX((Case when RELATED(AuctionsSage[idSIte] in (0,1,5) then haulage_base else haulage_auction END)))."

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@donnellyk In DAX you use SWITCH statement instead of CASE


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@donnellyk In DAX you use SWITCH statement instead of CASE


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks, got it working with a SWITCH

 

CustomHaulage = SWITCH(
TRUE (),
RELATED(OtherTable[idSIte])="0", thistable[haulage_base],
RELATED(OtherTable[idSIte])="1", thistable[haulage_base],
RELATED(OtherTable[idSIte])="5", thistable[haulage_base],
thistable[haulage_auction]
)

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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