Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX SWITCH FORMULA SHOWING INCORRECT GROUPING

Hi,

 

I'm trying to create a DAX formula using switch. I need to group all negative numbers to display no_new_return|prev rtn. However, some negative numbers are falling into other groups designated for positive values. Example -41 is falling in other groups such as 0-21,22-30 etc. as highlighted in the below image. The formula works for numbers > 0 but the negatives are not being recognized. Any assistance is appreciated. 

 

formula : 

ORD_RCPT_TENURE_GROUP = SWITCH(TRUE(),'FF_ORDER_MST'[ORD_RCPT_TENURE]<0,"NO_NEW_RTN | PREV RTN",'FF_ORDER_MST'[ORD_RCPT_TENURE]>=0 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=21,"0-21",'FF_ORDER_MST'[ORD_RCPT_TENURE]>21 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=30,"22-30",'FF_ORDER_MST'[ORD_RCPT_TENURE]>30 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=60,"31-60",'FF_ORDER_MST'[ORD_RCPT_TENURE]>60 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=90,"61-90",'FF_ORDER_MST'[ORD_RCPT_TENURE]>90 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=120,"91-120",'FF_ORDER_MST'[ORD_RCPT_TENURE]>120 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=180,"121-180",'FF_ORDER_MST'[ORD_RCPT_TENURE]>180 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=365,"181-365",'FF_ORDER_MST'[ORD_RCPT_TENURE]>365,"+365","NO_NEW_RTN | PREV RTN")the value -41 is showing in 3 different groups.
  • Hi Anonymous ,

     

    Your MEASURE [ORD_RCPT_TENURE] seems to involve two tables? This seems to be the source of the problem. What exactly do these two tables look like? What is the relationship between them?

    Sorry for that the information you have provided is not making the problem clear to me. Can you please share more details to help us clarify your scenario?

    Please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

     

    Refer to:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

     

    Best Regards,

    Jianbo Li

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

4 Replies

  • hi Anonymous 

    what column/measure do you have for the table visual?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello,

     

    measure: 

    ORD_RCPT_TENURE = DATEDIFF(MAXX(FF_ORDER_MST,'FF_ORDER_MST'[CPE_ORDER_DUE_DT]),MAXX(Recpt_Combined,'Recpt_Combined'[RECPT_DATE]),
    DAY)
     
    calculated column : 
    ORD_RCPT_TENURE_GROUP = SWITCH(TRUE(),'FF_ORDER_MST'[ORD_RCPT_TENURE]<0,"NO_NEW_RTN | PREV RTN",'FF_ORDER_MST'[ORD_RCPT_TENURE]>=0 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=21,"0-21",'FF_ORDER_MST'[ORD_RCPT_TENURE]>21 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=30,"22-30",'FF_ORDER_MST'[ORD_RCPT_TENURE]>30 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=60,"31-60",'FF_ORDER_MST'[ORD_RCPT_TENURE]>60 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=90,"61-90",'FF_ORDER_MST'[ORD_RCPT_TENURE]>90 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=120,"91-120",'FF_ORDER_MST'[ORD_RCPT_TENURE]>120 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=180,"121-180",'FF_ORDER_MST'[ORD_RCPT_TENURE]>180 && 'FF_ORDER_MST'[ORD_RCPT_TENURE]<=365,"181-365",'FF_ORDER_MST'[ORD_RCPT_TENURE]>365,"+365","NO_NEW_RTN | PREV RTN")
  • Hi Anonymous ,

     

    Your MEASURE [ORD_RCPT_TENURE] seems to involve two tables? This seems to be the source of the problem. What exactly do these two tables look like? What is the relationship between them?

    Sorry for that the information you have provided is not making the problem clear to me. Can you please share more details to help us clarify your scenario?

    Please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

     

    Refer to:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

     

    Best Regards,

    Jianbo Li

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      It was the relationship between the two tables. Thank you!