cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mmgnln
Helper II
Helper II

Week grouping

Hi guys,

 

I'm trying to group my dates by week and used the Grouping function and it worked ok. But I'd like to group by the week ending date and not by the week starting like it is doing right now. For example when I put the data on a matrix I see the following dates
12/15/2019 , 12/22/2019 - which are my week start dates

but I would like to see 12/14/2019 , 12/21/2019, 12/28/2019 instead which are my week ending dates.  Any ideas how to achieve that?

Week Grouping.JPG

Thank youuu!!

 
1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @mmgnln 

 

Try this Column.

Column 2 = 
VAR __yearWeek = FORMAT( 'Calendar'[Date], "YYYYWW" )
RETURN
CALCULATE(
    MAX( 'Calendar'[Date] ),
    ALL( 'Calendar' ),
    FORMAT( 'Calendar'[Date], "YYYYWW" ) = __yearWeek
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

View solution in original post

9 REPLIES 9
v-lili6-msft
Community Support
Community Support

hi @mmgnln 

You could use this formula to create a calculate column as below:

New week = var _bin= INT(DATEDIFF(DATE(2019,12,14),'Date'[Date],DAY)/7) return
CALCULATE(MIN('Date'[Date]),FILTER('Date', INT(DATEDIFF(DATE(2019,12,14),'Date'[Date],DAY)/7)=_bin))

 

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Mariusz
Community Champion
Community Champion

Hi @mmgnln 

 

Try this Column.

Column 2 = 
VAR __yearWeek = FORMAT( 'Calendar'[Date], "YYYYWW" )
RETURN
CALCULATE(
    MAX( 'Calendar'[Date] ),
    ALL( 'Calendar' ),
    FORMAT( 'Calendar'[Date], "YYYYWW" ) = __yearWeek
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

View solution in original post

@Mariusz thank  you! this worked!

@Mariusz sorry to go back to this but the calculation seems to have an issue with the year end. For example it groups the week of 12/28  (from 12/22 to 12/28) and then it groups 29,30,31/12 as 31/12 and then 01,02,03,04/01 as another group. Do you have any idea on how to fix this? Thank you!!

Mariusz
Community Champion
Community Champion

Hi @mmgnln 

 

You can add a column in the query editor, like below.

 image.png

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

Thanks Mariusz but in this case I would be using a Date table that was created using Dax, therefore it doesn't not show on the Power Query Editor. How can I go about that?

amitchandak
Super User
Super User

You can create a Date table and there you can have week start and week end dates. and group as per need

 

Week Start date = DATEADD('Compare Date'[Compare Date],-1*WEEKDAY('Compare Date'[Compare Date])+1,DAY)
Week End date = DATEADD('Compare Date'[Compare Date],7-1*WEEKDAY('Compare Date'[Compare Date]),DAY)

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Thank you @amitchandak but after WEEKDAY is calling another function or measure and doesn't allow me to call the table, do you know why? thanks!

Week End date = DATEADD('Compare Date'[Compare Date],7-1*WEEKDAY('Compare Date'[Compare Date]),DAY)

 

Hope you have done changes required in formula to suite your table. Can you share formula, relation and error.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.