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
Lolu
Regular Visitor

Hi Guys, I had this working in Tableau and trying to rewrite it in Power Bi (Dax)

 

In Tableau I approached this IF statement below by creating a parameter for each item [More than a week], [Missed this week], [Second Warning] and [First Warning] all as parameter and carried out an IF statement.

In using Power BI I am not sure what the best apporach is and if an IF statement is still applicable.

How can i approach this pleas, any comments assistance would be much appreciated.

IF
[CountDown]  < [More than a week] then
'More than a week'

ELSEIF
[CountDown] < [Missed this week] THEN
'Missed this week'

ELSEIF
[CountDown] < [Second Warning] THEN
'Second Warning'

ELSEIF
[CountDown] < [First Warning] THEN
'First Warning'
ELSE
'No Warning'

END

 

Many Thanks

L

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

@Lolu,

 

Hi L,

 

I hope your parameters are either whole number or decimal number. There is a latest function "what-if" may help.

 

Test =
IF (
    [CountDown] < [More than a week Value],
    "More than a week",
    IF (
        [CountDown] < [Missed this week Value],
        "Missed this week",
        IF (
            [CountDown] < [Second Warning Value],
            "Second Warning",
            IF ( [CountDown] < [First Warning Value], "First Warning", "No Warning" )
        )
    )
)

Hi Guys, I had this working in Tableau and trying to rewrite it in Power Bi (Dax).jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1. You can change these parameters dynamically.

2. Only three data types by now.

3. One table for one parameter.

Reference: https://www.youtube.com/watch?v=ND8U0yXroaQ&feature=youtu.be&t=1549

 

Best Regards!

Dale

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

View solution in original post

5 REPLIES 5
v-jiascu-msft
Employee
Employee

@Lolu,

 

Hi L,

 

I hope your parameters are either whole number or decimal number. There is a latest function "what-if" may help.

 

Test =
IF (
    [CountDown] < [More than a week Value],
    "More than a week",
    IF (
        [CountDown] < [Missed this week Value],
        "Missed this week",
        IF (
            [CountDown] < [Second Warning Value],
            "Second Warning",
            IF ( [CountDown] < [First Warning Value], "First Warning", "No Warning" )
        )
    )
)

Hi Guys, I had this working in Tableau and trying to rewrite it in Power Bi (Dax).jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1. You can change these parameters dynamically.

2. Only three data types by now.

3. One table for one parameter.

Reference: https://www.youtube.com/watch?v=ND8U0yXroaQ&feature=youtu.be&t=1549

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

That is not the correct syntax for an if statement, IF statements in DAX look like:

 

IF([CountDown]  < [More than a week],
     'More than a week',
     IF([CountDown] < [Missed this week],
          'Missed this week',
          IF([CountDown] < [Second Warning],
               'Second Warning',
               IF([CountDown] < [First Warning],
                    'First Warning',
                    'No Warning'
               )
           )
      )
)

 

That being said, I would go with a SWITCH statement.

https://msdn.microsoft.com/en-us/library/gg492166.aspx


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

Hi Smoupre,

is there any benefit having these items [More than a week], [Missed this week] etc as parameters in Power BI?

 

 

Also the if statement seems to be working, but what might be the advantage of a switch over if in this case.

Many Thanks

L

 

 

Developer types always tell me that a switch statement is preferred over an if statement for purposes of readability, logic flow, etc.

 

https://stackoverflow.com/questions/449273/why-the-switch-statement-and-not-if-else

 


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

Hi Smoupre,

is there any benefit having these items [More than a week], [Missed this week] etc as parameters in Power BI?

 

 

Also the if statement seems to be working, but what might be the advantage of a switch over if in this case.

Many Thanks

L

 

 

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.