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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

 

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

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

 

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.
Anonymous
Not applicable

@Mariusz thank  you! this worked!

Anonymous
Not applicable

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

 

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.

 

Anonymous
Not applicable

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

Anonymous
Not applicable

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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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