Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

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"))))))
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@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 YouTube.gif 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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@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 YouTube.gif 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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.

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.

CamilaPenaranda_0-1661894509453.png

 

parry2k
Super User
Super User

@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 YouTube.gif 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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.