Forum Discussion

zhblack's avatar
zhblack
Regular Visitor
7 years ago
Solved

If and formula

I am trying to identify if an item is an outage. An outage is when day 1 is less than 1 and uasge within last year is greater than 1. 

 

= Table.AddColumn(#"Expanded Usage_MRP_K", "Custom", each IF( And(  value([Day1])<1, value([Usage_MRP_K.Usage Within Last Year])>1 ) ,"Outage", "No Outage"))

 

I get the following error message when I enter the above formula. 

 

Expression.Error: The name 'IF' wasn't recognized.  Make sure it's spelled correctly.

  • The Query Editor uses a syntax called "M" that differs from the syntax used in Excel.  It is also case sensitive.  The below statement should get what you need based on how you wrote your if statement:

     

    if [Day1] < 1 and [Usage_MRP_K.Usage Within Last Year] >1 then "Outage" else "No Outage"

     

    If you need additional help, the article below is a good reference:

     

    https://www.myonlinetraininghub.com/power-query-if-statements

2 Replies

  • drewlewis15's avatar
    drewlewis15
    Icon for Solution Specialist rankSolution Specialist

    The Query Editor uses a syntax called "M" that differs from the syntax used in Excel.  It is also case sensitive.  The below statement should get what you need based on how you wrote your if statement:

     

    if [Day1] < 1 and [Usage_MRP_K.Usage Within Last Year] >1 then "Outage" else "No Outage"

     

    If you need additional help, the article below is a good reference:

     

    https://www.myonlinetraininghub.com/power-query-if-statements

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi zhblack

    Modify your formula as drewlewis15's suggestion, it turns out to be right.

    Table.AddColumn(#"Changed Type", "Custom", each if [Day1] < 1 and [Usage_MRP_K.Usage Within Last Year] >1 then "Outage" else "No Outage")

     

    Best Reagrds

    Maggie