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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Last "n" days/weeks based on selected values

Dear All, 

 

I got a fact and date dimension linked each other, objective is to get the last "n" weeks based on select week from slicer.

Suppose says selected week is W14-19, and want to see trend of last 8 weeks,  then sales should show from W07-19 to W14-16

Would it possible to have this achived, pls do suggest.

 

Thanks

4 REPLIES 4
v-cherch-msft
Employee
Employee

Hi @Anonymous 

You need a calendar table with a unique Week ID column. For further:

http://exceleratorbi.com.au/power-pivot-calendar-tables/

As as long as you have a unique week ID column, you can write a formula like below:

Last 8 Weeks =
CALCULATE (
    [Total Sales],
    FILTER (
        ALL ( Calendar ),
        Calendar[WeekID]
            >= MAX ( Calendar[WeekID] ) - 7
            && Calendar[WeekID] <= MAX ( Calendar[WeekID] )
    )
)

Here is the post about last n months for your reference.

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks @v-cherch-msft , this does gives last N weeks sales, but the it aggregates against the selected values and cant group based on weeks, however this post helped, but the DATESINPERIOD doesnt accept Week, instead of week have tried for DAY by converting weeks into days, but the problem is at year end, trying to figure this out.

Hi @Anonymous 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution and welcome to share your own solution. More people will benefit from here. If not, please share more details for us so that we could help further on it.

Regards,

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

Hi @Anonymous 

Could you share some sample data?Sample data and expected output will be helpful to provide an accurate solution.

It would be better if you can upload the .pbix file to OneDrive and post the link here. Do mask sensitive data before uploading.

Regards,

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors