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
Anonymous
Not applicable

Dax Switch statement - Need help in implementation

Hi ,

 

I need to implement a below logic in Power BI using DAX. I  am unable to call the other tables(Purchase[Last_day],Timedim[Last_Day]) in the switch condition. 

 

case when (( SALES.REQUEST_DT ) is null) or ( SALES.REQUEST_DT ) >= to_date('1-12-2005','MM-DD-YYYY') then 'P'
when ( SALES.REQUEST_DT )<=( Purchase.Last_Day ) then 'PDue'
when ( SALES.REQUEST_DT ) between to_date('08-10-2010','MM-DD-YYYY') and to_date('10-11-2010','MM-DD-YYYY') then 'BO'
when ( SALES.REQUEST_DT ) between ( Timedim.Last_Day )+1 and to_date('01-10-2010','MM-DD-YYYY') then 'After'
else
to_char(to_date(Customer_Dt.FISCAL_MONTH || '/' || Customer_Dt.FISCAL_YEAR,'MM/YYYY'),'MON-YY')
end

 

Need help how to implement this using Power BI. Any help is highly appreciated.

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

@Anonymous - Sure, you can do that using RELATED or RELATEDTABLE if they are related and using LOOKUPVALUE or MAXX(FILTER('Other Table',<filter criteria>),<column in other table>)


@ 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

5 REPLIES 5
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create relationships between the table 'SALES' and  'Purchase',  'SALES' and  'Timedim' on related date with Both of Cross filter direction, or these tables have been linked by intermediate tables such as Calendar table,  then use RELATED function to get Purchase[Last_day] and Timedim[Last_Day] in formula.

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

pranit828
Community Champion
Community Champion

HI @Anonymous 

Enclose it in SELECTEDVALUE() function, like below.

(SELECTEDVALUE(Purchase[Last_day]),SELECTEDVALUE(Timedim[Last_Day])) 

 





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile
Greg_Deckler
Super User
Super User

@Anonymous - Use SWITCH(TRUE()...)

 

 


@ 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...
Anonymous
Not applicable

Hi @Greg_Deckler ,

 

I tried using switch ( true()..) but my corncern over here is i am unable to call the other table (Purchase) to compare dates. Is there a way to implement it.

 

Thanks.

@Anonymous - Sure, you can do that using RELATED or RELATEDTABLE if they are related and using LOOKUPVALUE or MAXX(FILTER('Other Table',<filter criteria>),<column in other table>)


@ 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...

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.