Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX Power BI- Need a help on Formula

Dear All,

 

I would apprecaite, if you could help me to find an error in the formula below.

 

Month_Groups = SWITCH(TRUE(),
AND(MYK_AD_20230428[Date_Month]<12),"Less than 12 Month",
 AND(MYK_AD_20230428[Date_Month]>12, MYK_AD_20230428[Date_Month]<24),"12-24",
  AND(MYK_AD_20230428[Date_Month]>24, MYK_AD_20230428[Date_Month]<36),"24-36",
  MYK_AD_20230428[Date_Month]>36,"36+", BLANK())
 
The error message as following: Too few arguments were passed to the AND function. The minimum argument count for the function is 2.
 
It should group the data after month. 
 
Thank you in advance. 
 
Best regards
Jelena
  • Hi Jelena,

     

    Thank you for your prompt response. Could you possibly please try the following:

    Month_Groups =
    SWITCH(
        TRUE(),
        MYK_AD_20230428[Date_Month] < 12, "Less than 12 Month",
        AND(MYK_AD_20230428[Date_Month] > 12, MYK_AD_20230428[Date_Month] < 24), "12-24",
        AND(MYK_AD_20230428[Date_Month] > 24, MYK_AD_20230428[Date_Month] < 36), "24-36",
        MYK_AD_20230428[Date_Month] > 36, "36+",
        BLANK()
    )

    Let me know if you might need further assistance.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Dear Sahir, thank you very much for your answer. Unfortunately, the error is the same. It shows, that there is an error in this line:

    AND(MYK_AD_20230428[Date_Month]<12),"Less than 12 Month",
     
    Thank you in advance. 
     
    Best regards,
    Jelena
    • Sahir_Maharaj's avatar
      Sahir_Maharaj
      Icon for Super User rankSuper User

      Hi Jelena,

       

      Thank you for your prompt response. Could you possibly please try the following:

      Month_Groups =
      SWITCH(
          TRUE(),
          MYK_AD_20230428[Date_Month] < 12, "Less than 12 Month",
          AND(MYK_AD_20230428[Date_Month] > 12, MYK_AD_20230428[Date_Month] < 24), "12-24",
          AND(MYK_AD_20230428[Date_Month] > 24, MYK_AD_20230428[Date_Month] < 36), "24-36",
          MYK_AD_20230428[Date_Month] > 36, "36+",
          BLANK()
      )

      Let me know if you might need further assistance.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Dear Sahir

         

        It worked, thank you very much. You are hero. 

         

        Best regards,

        Jelena

  • Hello Anonymous,

     

    To fix this issue, you need to modify the formula as follows:

     

    Month_Groups = SWITCH(TRUE(),
        AND(MYK_AD_20230428[Date_Month]<12),"Less than 12 Month",
        AND(MYK_AD_20230428[Date_Month]>12, MYK_AD_20230428[Date_Month]<24),"12-24",
        AND(MYK_AD_20230428[Date_Month]>24, MYK_AD_20230428[Date_Month]<36),"24-36",
        MYK_AD_20230428[Date_Month]>36,"36+",
        BLANK()
    )

     

    The error in the formula is related to the usage of the AND function. The AND function requires a minimum of two arguments, but in the formula you provided, some of the AND functions have only one argument.

     

    Let me know if you might need further assistance.