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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
itsmebvk
Continued Contributor
Continued Contributor

Last N Weeks not showing as expected based on slicer selection?

Hi Experts,

 

I tried many ways and refereed similar threads in this forum, however I am unable to achieve the output I am looking for. I am trying to get last four weeks based on “Year week” selection in slicer for example if I select 202110, I want to see 202107 to 202110.

 

I tried it different way using the method mentioned below screenshot, but its not working 100%. Yearweek slicer was showing 202190 week 😊which doesn’t make sense.

 

 

itsmebvamsi_0-1646187902310.png

 

 

 

Can you please see the attached sample file and suggest me better way of achieving this requirement.

 

Thank you.

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @itsmebvk ,

 

Please create a separate table:

 

YearWeek = VALUES('Date Table'[Calendar_YearWeek])

vkkfmsft_0-1646379033557.png

 

Then create the measure:

 

Rolling_4 = 
VAR yearweektab =
    CALCULATETABLE (
        VALUES ( 'Date Table'[Calendar_YearWeek] ),
        FILTER (
            ALL ( 'Date Table' ),
            'Date Table'[Calendar_Date]
                >= MIN ( 'Date Table'[Calendar_Date] ) - 21
                && 'Date Table'[Calendar_Date] <= MAX ( 'Date Table'[Calendar_Date] )
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Measure'[Measure] ),
        FILTER (
            yearweektab,
            [Calendar_YearWeek] = MAX ( YearWeek[Calendar_YearWeek] )
        )
    )

vkkfmsft_1-1646379096495.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

2 REPLIES 2
v-kkf-msft
Community Support
Community Support

Hi @itsmebvk ,

 

Please create a separate table:

 

YearWeek = VALUES('Date Table'[Calendar_YearWeek])

vkkfmsft_0-1646379033557.png

 

Then create the measure:

 

Rolling_4 = 
VAR yearweektab =
    CALCULATETABLE (
        VALUES ( 'Date Table'[Calendar_YearWeek] ),
        FILTER (
            ALL ( 'Date Table' ),
            'Date Table'[Calendar_Date]
                >= MIN ( 'Date Table'[Calendar_Date] ) - 21
                && 'Date Table'[Calendar_Date] <= MAX ( 'Date Table'[Calendar_Date] )
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Measure'[Measure] ),
        FILTER (
            yearweektab,
            [Calendar_YearWeek] = MAX ( YearWeek[Calendar_YearWeek] )
        )
    )

vkkfmsft_1-1646379096495.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

@itsmebvk , if you select a week and need 4 weeks. Then week slicer should be in an independent date table

 

You need rank of year week in date 1 and date table

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Week Rank])
var _min = _max -4
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Week Rank] >=_min && 'Date'[Week Rank] <=_max))

 

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

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

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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