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
mdrammeh
Helper III
Helper III

IF function with multiple criteria

I need help creating a calculated field column in Power Query using the following criteria:

=IF([@[DESIGN DOLLARS]]=MAX(EY14:EY15180),"BEST PERFORMING YEAR",IF([@[DESIGN DOLLARS]]=MIN(EY14:EY15180),"LEAST PERFORMING YEAR",""))

I need a way to convert the following formula into Power Query language so that I could add a column to show these performances.

 

For a simlar view, to capture the following measures:

If the Cell value is in between 1-5 then "1-5 days".

If the Cell value is in between 6-10 then "6-10 days".

If the Cell value is in between 11-20 then "11-20 days".

If the Cell value is in between 21-30 then "21-30 days".

If the Cell value is greater than 30 than "greater than 30"

 

You assistance is highly appreciate.

 

Than you!

7 REPLIES 7
GilbertQ
Super User
Super User

You could complete it by clicking on Add Column in the ribbon, then "Add Custom Column"

 

Then you can put in the following syntax:

 

NOTE: When using the Power Query Language it is case sensitive.

 

if [Cell Value] >= 1 and [Cell Value] <= 5 then "1-5 Days"

else if [Cell Value] >= 6 and [Cell Value] <= 10 then "6-10 Days"

else if [Cell Value] >= 11 and [Cell Value] <= 20 then "11-20 Days"

else if [Cell Value] >= 21 and [Cell Value] <= 30 then "21-30 Days"

else "greater than 30"

 

That should be all you need on your new Custom Column





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Greg_Deckler
Super User
Super User

Sorry, which formula are you trying to create in Power Query? Is it:

 

=IF([@[DESIGN DOLLARS]]=MAX(EY14:EY15180),"BEST PERFORMING YEAR",IF([@[DESIGN DOLLARS]]=MIN(EY14:EY15180),"LEAST PERFORMING YEAR",""))

 

or:

 

If the Cell value is in between 1-5 then "1-5 days".

If the Cell value is in between 6-10 then "6-10 days".

If the Cell value is in between 11-20 then "11-20 days".

If the Cell value is in between 21-30 then "21-30 days".

If the Cell value is greater than 30 than "greater than 30"

 

And does it have to be done in Power Query or could it be done in the data model in DAX? And does it need to be column or could it be a measure. Finally, some sample data and expected results would greatly help!


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

They are two separate examples. The first example would be something like this where am trying to capture the best performing year in Power Query. I want the formula to be in a separate column as shown here within the "Query Editor". 

 

In other words, how would you translate this "=IF([@[Estimated Dollars]]=MAX([Estimated Dollars]),"BEST PERFORMING YEAR",IF([@[Estimated Dollars]]=MIN([Estimated Dollars]),"LEAST PERFORMING YEAR",""))" in DAX using the M language?

 

Fiscal YearEstimated DollarsActual DollarsPerformance
1/1/20161.002LEAST PERFORMING YEAR
1/2/201610.0020 
1/3/201620.0021 
1/4/201630.0022 
1/5/201611.0031 
1/6/201612.0012 
1/7/201613.0013 
1/8/201621.0043 
1/9/201622.0034 
1/10/201623.0022 
1/11/201633.0014 
1/12/201644.0044 
1/13/201645.0045BEST PERFORMING YEAR

 

In the second example, I want to create a look up to a certain range and return a specific result where that measure exists.

 

For example, if the difference between the Estimated Dollars and Actual Dollars is greater than +/_10%, return the following " Out of Tolerance". And if the difference between Estimated Dollars and Actual Dollars is within +/_10%,, return the following: "Within Tolerance" . Thirdly, If the difference is +/-10% and has a value less than +/-10.00, return the following "Review Estimate". 

 

Sorry this scenario is a little different than what I wrote but the challenge am having here is how to transform DAX into Power Query language. 

OK, for your second revised example, you could create three custom columns in Power Query:

 

Percent Difference = Number.Abs(([Estimated Dollars] - [Actual Dollars]) / [Estimated Dollars])

Difference = Number.Abs([Estimated Dollars] - [Actual Dollars])

Tolerance = if [Percent Difference] > .1 then "Out of Tolerance" else if [Difference] < 10 then "Review Estimate" else "Within Tolerance"

For the first one, the MAX query, that is something that is trivial in DAX but not necessarily in "M" code. @ImkeF might have some insights into how to do that, she is the resident "M" wizard. I'll take a look but by the time I figure it out, @ImkeF will have probably already posted the answer 3 days before. I imagine it will involve something like List.Max.


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

I received the following error message when I tried the percentage change formula:

 

"DataSource.Error: An error happened while reading data from the provider: 'The provider could not determine the Double value. For example, the row was just created, the default for the Double column was not available, and the consumer had not yet set a new Double value.'

 

Thanks for being patient with me. I am very new to this whole power query thing and trying to learn the hard way 🙂

Never seen an error-message like this before. Sure that's due to the percentage change formula and not somewhere before?

 

Have you specifically applied a number format to the respective columns before? You should do that.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

🙂

 

if [Actual Dollars]=List.Max(NameOfPreviousStep[Actual Dollars]) then "Best performing" else if [Actual Dollars]=List.Min(NameOfPreviousStep[Actual Dollars]) then "Worst performing" else ""

 

The challenge here is to apply the List.Max correctly: It should look into the Actual Dollars-Column, but if you reference it within a calculated column like this: [Actual Dollars], you will only get this columns value of the current row (and not the whole column). This is a behaviour that is most often wanted for operations performed in additional columns and has therefore been made as the default setting by turning everything you paste into the editor-field into a function (that takes in the current row as it's input) (btw: if you look into the formula editor you'll see that your input into the editor is proceeded by "each" - this is a shortterm for a function)

 

So in order to reference a whole column within an added custom step you reference the previous step (by simply writing it's name - but don't forget the #"..." if needed), followed by the columm name in spuare brackets.

 

Hope this makes sense?

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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.

Top Solution Authors