Forum Discussion

ACraig08's avatar
ACraig08
Helper III
3 years ago
Solved

IF Condition with IN Function

So I am trying to create a column based off of date column in order to have the quarters line up with my agencies quarters. I can't seem to figure out why it is giving me a token error and expecting a parenthesis. 

This is the code written out in case that helps:

if(Date.Month([Date]) in {7,8,9}, "Q1",
  if(Date.Month([Date]) in {10,11,12}, "Q2",
    if(Date.Month([Date]) in {1,2,3}, "Q3",
      if(Date.Month([Date]) in {4,5,6}, "Q4",""))))

 

It is saying that it is expecting an outer parenthesis in the area I highlighted in red and I can't seem to figure out why!

  • Hi , ACraig08 

    According to your M code , The syntax of M language is different from dax.

    You can use this M code yo get your resullt :

    if List.Contains({7,8,9}, Date.Month([Date])) then  "Q1" else if  List.Contains({10,11,12}, Date.Month([Date])) then  "Q2" else if  List.Contains({1,2,3}, Date.Month([Date])) then  "Q3"  else if  List.Contains({4,5,6}, Date.Month([Date])) then  "Q4" else ""

     

    The result is as follows:

     

     

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

1 Reply

  • Hi , ACraig08 

    According to your M code , The syntax of M language is different from dax.

    You can use this M code yo get your resullt :

    if List.Contains({7,8,9}, Date.Month([Date])) then  "Q1" else if  List.Contains({10,11,12}, Date.Month([Date])) then  "Q2" else if  List.Contains({1,2,3}, Date.Month([Date])) then  "Q3"  else if  List.Contains({4,5,6}, Date.Month([Date])) then  "Q4" else ""

     

    The result is as follows:

     

     

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly