cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Musketeers
Regular Visitor

if else condition with between operator

Hi,

I am using M language and adding a new column in table.

I need to write if condition in this line.

I am writing if condition like this:

if [Month] between 2 and 4 then "yes" else "no"

 

Now here I am getting error for between key word. 

Please tell me what is the error and what is the correct way of writng this condition.

 

 

Thanks

Rajneesh

 

1 ACCEPTED SOLUTION

Hi

 

You can do this

 

if [Month] >= 2 and [Month] <= 4 then "yes" else "no"

 

 

 

/Erik

View solution in original post

7 REPLIES 7
JPBTech19
Frequent Visitor

The following should work:

    IF
    (
        AND                                                   Operational condition
            (
                [Month]>= 2, [Month]<=4        Conditional statement being evaluated
            ),

            "YES",                                             Result is condition is TRUE
            "NO"                                              Result is condition is FALSE
    )

 

Written another way...

 

    IF(AND([Month]>= 2, [Month]<=4),"YES","NO")

Hi

 

You can do this

 

if [Month] >= 2 and [Month] <= 4 then "yes" else "no"

 

 

 

/Erik

Hi Erik,

Thanks for your reply.

Yes you are right. This is also a another way to do this.

But wanted to know if we can write this with Between Keyword as I was trying to write.

 

 

Any way I will use the way you have suggested. 

 

 

Thanks

Rajneesh

@Musketeers

 

In Power Query, there's no "between" keyword, you can only use operators to achieve this kind of logic as @donsvensen suggested.  

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

 

Regards,

 

Hi Simon, Thanks for your suggestion. Yes that way it is working. Thanks all for your time and suggestions.

osiel
Frequent Visitor

hello, it still works so I've tried and it does not work for me the only thing is that I'm using dates and looking for a date within this range, for example:

Start date: 01-01-18
Final Date: 08-01-18
date to search: 05-01-17
if the date is within the range that returns me a value of $ .100.
thanks for your comments. regards osiel

osiel
Frequent Visitor

hello, it still works so I've tried and it does not work for me the only thing is that I'm using dates and looking for a date within this range, for example:

Start date: 01-01-18
Final Date: 08-01-18
date to search: 05-01-17
if the date is within the range that returns me a value of $ .100.
thanks for your comments. regards osiel

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors