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

Couple of DAX questions around IF Statements

Hello,  Hoping you can help me with solving my two problems below. 

 

Problem One- Write these two statements in DAX- I copy and pasted what I use in Alteryx

 

2019 Outlet Status

If DateTimeYear([Outlet Max_Week Ending])=2018 then "Lost"
elseif DateTimeYear([Outlet Min_Week Ending])=2019 then "New"
elseif DateTimeYear([Outlet Min_Week Ending])= 2020 then "Other"
else "Active"
endif

 

2020 Outlet Status

If DateTimeYear([Outlet Max_Week Ending])=2019 Then "Lost"
elseif DateTimeYear([Outlet Min_Week Ending])=2020 then "New"
elseif DateTimeYear([Outlet Max_Week Ending])=2018 then "Other"
else "Active"
endif

 

Problem Two -Switch between the two variables above depending on the Slicer Selection

 

Selected Period Volume =
VAR PERSELECT =
SELECTEDVALUE ( 'Period Select (2)'[Period Selector])
RETURN
SWITCH (
PERSELECT,
"YTD",2020 Outlet Status,
"MTD", 2020 Outlet Status,
"2019", 2019 Outlet Status,
"Rolling 13 Weeks", 2020 Outlet Status,
"Pre-Covid W1-W9", 2020 Outlet Status,
"Prior 4wks", 2020 Outlet Status,
"Prior 13wks", 2020 Outlet Status,
"Prior 26wks", 2020 Outlet Status,
"Prior 52wks", 2020 Outlet Status)
 
Thanks for your help in advance. 
 
bret
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

You need to write the DAX version as follows for the first problem, I hope they are added as a calculated column.
2nd Problem is Measure I believe. You can adapt in the same way. I need more clarification on the second one, better if you could attach a sample PBIX file.

2019 Outlet Status = 

SWITCH( TRUE() , 
    DateTimeYear[Outlet Max_Week Ending] = 2018, "Lost",
    DateTimeYear[Outlet Min_Week Ending] = 2019,  "New",
    DateTimeYear[Outlet Min_Week Ending] = 2020, "Other",
    "Active"
)


2020 Outlet Status = 

SWITCH( TRUE(),

    DateTimeYear[Outlet Max_Week Ending] = 2019, "Lost",
    DateTimeYear[Outlet Min_Week Ending] = 2020, "New",
    DateTimeYear[Outlet Max_Week Ending] = 2018, "Other",
    "Active"
)

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@Anonymous - Don't use nested IF ELSE statements, use SWITCH() or 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...
Fowmy
Super User
Super User

@Anonymous 

You need to write the DAX version as follows for the first problem, I hope they are added as a calculated column.
2nd Problem is Measure I believe. You can adapt in the same way. I need more clarification on the second one, better if you could attach a sample PBIX file.

2019 Outlet Status = 

SWITCH( TRUE() , 
    DateTimeYear[Outlet Max_Week Ending] = 2018, "Lost",
    DateTimeYear[Outlet Min_Week Ending] = 2019,  "New",
    DateTimeYear[Outlet Min_Week Ending] = 2020, "Other",
    "Active"
)


2020 Outlet Status = 

SWITCH( TRUE(),

    DateTimeYear[Outlet Max_Week Ending] = 2019, "Lost",
    DateTimeYear[Outlet Min_Week Ending] = 2020, "New",
    DateTimeYear[Outlet Max_Week Ending] = 2018, "Other",
    "Active"
)

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.