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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mim
Advocate V
Advocate V

group by dynamic week

I have this calendar that calculated week based on a particular weekend, which is the last date from another table using this measure "Cutt off daily", everything was fine, untill someone wanted a slicer but as you know calculated column can not change calcultion based on another slicer or filter, is there any workaround

weekend.JPG

 

 
1 ACCEPTED SOLUTION
Brian_M
Responsive Resident
Responsive Resident

Note that the Calendar table has to be marked as a date table for the time intelligence (DATESBETWEEN) functions to work.

 

Based on your response on twitter, the pbix file also has a YTD version for the sum of qty.

 

Hope that helps!

View solution in original post

6 REPLIES 6
Brian_M
Responsive Resident
Responsive Resident

I undesrtand you wish to group all of the sales for each given week into a seven day period ending on the same day of the week as the selected slicer.

 

The measure below checks to see if our date on the X-axis is the same day of the week as your slicer. If not it returns BLANK( ), if it is the same day of week, it sums the qty for the previous 7 days.

 

Qty at 'week end' =
VAR SelectedSlicerDate =
    SELECTEDVALUE ( 'Slicer Dates'[Date] )
VAR ThisDateOnAxis =
    SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
    IF (
        WEEKDAY ( SelectedSlicerDate ) <> WEEKDAY ( ThisDateOnAxis ),
        BLANK (),
        CALCULATE (
            SUM ( 'Data Table'[qty] ),
            DATESBETWEEN ( 'Calendar'[Date], ThisDateOnAxis - 6, ThisDateOnAxis )
        )
    )

 

I'll attempt to link to a copy of the pbix

Example PBIX file 

Brian_M
Responsive Resident
Responsive Resident

Note that the Calendar table has to be marked as a date table for the time intelligence (DATESBETWEEN) functions to work.

 

Based on your response on twitter, the pbix file also has a YTD version for the sum of qty.

 

Hope that helps!

Brian_M
Responsive Resident
Responsive Resident

Is there an example file we can have a crack at, would love to give it a go!

v-xicai
Community Support
Community Support

Hi @mim ,

 

You couldn't have a calculated column interacted with a slicer or interaction , since columns are only calculated when data is loaded/refreshed.  So you may need to click "Refresh" button for every time you make filter in slicer or interact with other visual.

 

In addition, you may create the [dynamic Week End] using measure instead of calculated column like DAX below, While it may not be displayed in Data view, you may show it in table visual using fields as you need.

 

dynamic Week End= MAX([Date]) -MOD(MAX([Date]) - WEEKDAY([Cutt off daily], 2) -2, 7)+6

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@mim ,Please if my blog can help you for week

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak  my case is different, my weekend is not fixed, basically, I want the weekend to change based on another measure

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.