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
whatisdata96
Helper I
Helper I

How to calculate last N periods? Periods in this case = WeekEnd Date - I want last 8 periods (weeks)

Hi all-

 

I'm looking to calculate last 8 weeks based on WeekEnd Date which I've already created a calculated column:

 

WeekEnd Date= dimCalendar[Date]+7-1*WEEKDAY(dimCalendar[Date],1)

 

Should I use a RANX formula to label the weeks?

 

I want to be able to show SUM for this period (week) and last 8 periods/weeks.

 

Would RANKX be a step in the right direction?


Then maybe create that aggregate measure saying SUM(COLUMN), FILTER(TODAY- Last 8 periods)?

 

I'm all over the place here. Would appreciate any help!

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

I think, becasue it is calculating week-base, perhaps it is better to use a simple calculation like 7 times 7 periods = 49 days.

Please check the below picture and the attached pbix file. I hope the below can provide some ideas on how to create a solution for your dataset.

 

Untitled.png

 

Sales last 8 weeks: =
VAR _todaysweekend =
    MAXX (
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] = TODAY () ),
        'Calendar'[WeekEnd Date]
    )
VAR _eightweeksperiodstartdate = _todaysweekend - 49
RETURN
    CALCULATE (
        [Sales measure:],
        KEEPFILTERS ( 'Calendar'[Date] >= _eightweeksperiodstartdate
            && 'Calendar'[Date] <= _todaysweekend )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
v-binbinyu-msft
Community Support
Community Support

Hi @whatisdata96 ,

I am really pleased that your issue has been fixed. Would you kindly share with us about your solution here? In this way, it will be beneficial to other community members as well.

 

Best regards,
Community Support Team_ Binbin Yu

whatisdata96
Helper I
Helper I

Wow this is wonderful. I wish I was able to do this on my own.

 

From what I understand, you first created a variable that selected the MAX TODAY WeekEnd Date, then another variable which takes that MAX WeekEND date - 49 days which captures all the data/dates needed for the pivot, correct?

 

Then Returning the aggregation using the 2 variables as parameters. Am I understanding this correctly?

 

 

Hi,

Thank you for your message, and you are correct. 🙂

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

I think, becasue it is calculating week-base, perhaps it is better to use a simple calculation like 7 times 7 periods = 49 days.

Please check the below picture and the attached pbix file. I hope the below can provide some ideas on how to create a solution for your dataset.

 

Untitled.png

 

Sales last 8 weeks: =
VAR _todaysweekend =
    MAXX (
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] = TODAY () ),
        'Calendar'[WeekEnd Date]
    )
VAR _eightweeksperiodstartdate = _todaysweekend - 49
RETURN
    CALCULATE (
        [Sales measure:],
        KEEPFILTERS ( 'Calendar'[Date] >= _eightweeksperiodstartdate
            && 'Calendar'[Date] <= _todaysweekend )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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