Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Date Range grouping

Hello,
 
I am trying to group tansactions by date ranges from day selected. I am using the code below to create the categories  but I keep getting the "60+ days" and no other categories. Can someone please help me figure out what's wrong with the dax?
 
Thank you!
 
Grouping =
Var Tabledate = DATEDIFF(Date],TODAY(),Day)
Return
if(
Tabledate<0 && Tabledate <3,"1-2 days",
if(
Tabledate>2 && Tabledate < 6,"3-5 days",
if(
Tabledate>5 && Tabledate < 16,"6-15 days",
if(
Tabledate>15 && Tabledate < 23,"16-22 days",
if(
Tabledate>22 && Tabledate< 31,"23-29 days",
if(
Tabledate>30 && Tabledate < 61,"30-60 days",
"60+ days"))))))
  • Anonymous well you tweak the code as it fits for you, I just provided the solution based on your original question.

     

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

4 Replies

  • Anonymous TRY THIS:

     

    Grouping =
    Var Tabledate = DATEDIFF(Date],TODAY(),Day)
    Return
    SWITCH ( TRUE() ,
      TableDate>=61, "60+ Days",
      Tabledate>=30, "30-60 days",
      Tabledate>=23, "23-29 days",
      Tabledate>=16, "16-22 days",
      Tabledate>=6, "6-15 days",
      Tabledate>=3, "3-5 days",
      Tabledate>=1, "1-2 days",
      "Less than 1 Day"
    )

     

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you! This worked. My only issues is that it looks the its going back its not taking "today" (8/30/2022" and moving forward. I tried to filter by the next 3 months but it removed the categories.

     

  • Anonymous well you tweak the code as it fits for you, I just provided the solution based on your original question.

     

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I mean I have. The tweaks I made are not looking into the future but either way thank you it really helped.