cancel
Showing results for
Did you mean:
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?

Thank youuu!!

1 ACCEPTED SOLUTION
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.
9 REPLIES 9
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:

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.
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.
Helper II

@Mariusz thank  you! this worked!

Helper II

@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!!

Community Champion

Hi @mmgnln

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

Best Regards,
Mariusz

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

Helper II

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?

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://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

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!
Helper II

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)`

Super User

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

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!

Announcements

#### Launching new user group features

Learn how to create your own user groups today!