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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Grouping Dates

So I’m working with date-data and want to make a new column (I will use this as a slicer in my report) to group dates according to following condition :

If date between 01-10-2019 and 22-10-2019 then group A

If date between 08-10-2019 and 29-10-2019 then group B  ** Here i want the overlapping dates from group A as well.

If date between 15-10-2019 and 05-11-2019 then group C and So on.  ** Here i want the overlapping dates from group A and group B as well.

 

 

I have tried the IF, OR, AND logic but it is just working for the first group.

 

Please let me know if anybody have any other function in your mind which could solve this issue.

7 REPLIES 7
az38
Community Champion
Community Champion

Hi @Anonymous 

Try to SWITCH, it will stop execute after first succesfull conditionand will help you to resolve overlapping issue

DateGroup = SWITCH(TRUE(),
DATESBETWEEN([Date], DATE(2019,10,1), DATE(2019,10,22)), "A",
DATESBETWEEN([Date], DATE(2019,10,8), DATE(2019,10,29)), "B",
DATESBETWEEN([Date], DATE(2019,10,15), DATE(2019,11,5)), "C",
"Undefined"
)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
spandy34
Responsive Resident
Responsive Resident

Hi

 

I have a similar query but I was wondering if, instead of having to update the values each year, we could set a start date say 11/10/21 and then every 28 days a new Period - like the example below.  I need them as period numbers based on a DateofVIsit value - and then for it to start back at Period 1 for the next year after 13 Periods.

 

spandy34_0-1656094342782.png

 

Anonymous
Not applicable

Grouping Date.PNGI'm getting the above error while using SWITCH(). 

 

@az38 

az38
Community Champion
Community Champion

Sorry, @Anonymous 

I gave you completely wrong statement

try

DateGroup = SWITCH(TRUE(),
[Date] >= DATE(2019,10,1) && [Date] <=  DATE(2019,10,22)), "A",
[Date] >= DATE(2019,10,8) && [Date] <=  DATE(2019,10,29)), "B",
[Date] >= DATE(2019,10,15) && [Date] <=  DATE(2019,11,5)), "C",
"Undefined"
)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

hi @az38  @Anonymous 

 

let say date is 2019/10/16. 

this date comes in all buckets but as per column it will always show "A" only. The first condtion of switch statement get satisfied and it will not check for next conditions.

 

@Anonymous  if you want the same solution then above solution will work.

 

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

Anonymous
Not applicable

 Hi @Anonymous 

 

what value you are expecting for 16-10-2019?

 

Anonymous
Not applicable

HI @Anonymous  I'm working with Sales data and here I want cumulative week as following :

 

So, Group "A" will show sales from 1, Oct 2019 to 22,Oct 2019

      Group "B" will show sales from 8, Oct 2019 to 29,Oct 2019 ** Here I want sales of last three weeks from group "A"

      Group "C" will show sales from 15, Oct 2019 to 05,Nov 2019 ** Here I want sales of from 15 till 05

      Group "D" will show sales from 22, Oct 2019 to 12,Nov 2019 and so on.

 

I will use these groups as a slicer or in bar chart to show/ filter sales according to week bucket.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.