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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
BI_Samurai
Frequent Visitor

Last 6 Weeks

Hello,

 

Could you help with me with a dax measure to calculate and display dynmically only last 6 weeks from the time period year-week selected in the slicer? Values should correspond with a single week result (no cumulative values are needed). Thank you.

BI_Samurai_0-1728482448285.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BI_Samurai ,

I create two tables as you mentioned.

Caleadar =
VAR StartYear =
    YEAR ( NOW () ) - 5
VAR EndYear =
    YEAR ( NOW () ) + 5
RETURN
    ADDCOLUMNS (
        CALENDAR ( DATE ( StartYear, 1, 1 ), DATE ( EndYear, 12, 31 ) ),
        "Year", YEAR ( [Date] ),
        "Date_Key", VALUE ( FORMAT ( [Date], "YYYYMMDD" ) ),
        "Month", MONTH ( [Date] ),
        "Month Name", FORMAT ( [Date], "MMMM" ),
        "Day", DAY ( [Date] ),
        "Year Month", VALUE ( FORMAT ( [Date], "YYYYMM" ) ),
        "Week", WEEKDAY ( [Date], 2 ),
        "Month Abbr", FORMAT ( [Date], "MMM" ),
        "Weekday Abbr", FORMAT ( [Date], "DDD" ),
        "Quarter", QUARTER ( [Date] ),
        "Quarter Name", "Q" & CONVERT ( QUARTER ( [Date] ), STRING )
    )
Year List =
SELECTCOLUMNS ( GENERATESERIES ( 2018, 2028, 1 ), "Year", [Value] )

vyilongmsft_0-1728529046122.png

vyilongmsft_1-1728529059577.png

Next I think you can create a measure and add it to Filter.

Is Show =
VAR SelectedYear =
    SELECTEDVALUE ( 'Year List'[Year] )
VAR CurrentYear =
    SELECTEDVALUE ( 'Caleadar'[Year] )
RETURN
    IF ( CurrentYear <= SelectedYear, "Y", "N" )

vyilongmsft_2-1728529213464.png

Finally you will get what you want.

vyilongmsft_3-1728529252337.png

 

 

 

Best Regards

Yilong Zhou

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

Hi @BI_Samurai ,

I create two tables as you mentioned.

Caleadar =
VAR StartYear =
    YEAR ( NOW () ) - 5
VAR EndYear =
    YEAR ( NOW () ) + 5
RETURN
    ADDCOLUMNS (
        CALENDAR ( DATE ( StartYear, 1, 1 ), DATE ( EndYear, 12, 31 ) ),
        "Year", YEAR ( [Date] ),
        "Date_Key", VALUE ( FORMAT ( [Date], "YYYYMMDD" ) ),
        "Month", MONTH ( [Date] ),
        "Month Name", FORMAT ( [Date], "MMMM" ),
        "Day", DAY ( [Date] ),
        "Year Month", VALUE ( FORMAT ( [Date], "YYYYMM" ) ),
        "Week", WEEKDAY ( [Date], 2 ),
        "Month Abbr", FORMAT ( [Date], "MMM" ),
        "Weekday Abbr", FORMAT ( [Date], "DDD" ),
        "Quarter", QUARTER ( [Date] ),
        "Quarter Name", "Q" & CONVERT ( QUARTER ( [Date] ), STRING )
    )
Year List =
SELECTCOLUMNS ( GENERATESERIES ( 2018, 2028, 1 ), "Year", [Value] )

vyilongmsft_0-1728529046122.png

vyilongmsft_1-1728529059577.png

Next I think you can create a measure and add it to Filter.

Is Show =
VAR SelectedYear =
    SELECTEDVALUE ( 'Year List'[Year] )
VAR CurrentYear =
    SELECTEDVALUE ( 'Caleadar'[Year] )
RETURN
    IF ( CurrentYear <= SelectedYear, "Y", "N" )

vyilongmsft_2-1728529213464.png

Finally you will get what you want.

vyilongmsft_3-1728529252337.png

 

 

 

Best Regards

Yilong Zhou

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

Kedar_Pande
Super User
Super User

Make sure you have a date table that includes columns for the year and week. Let’s assume your date table is named DateTable and it contains a column named jahr_woche.

DAX measure:

Last6WeeksValue = 
VAR SelectedWeek = SELECTEDVALUE(DateTable[jahr_woche]) // Get the selected year-week from slicer
VAR SelectedDate = 
    MAXX(
        FILTER(DateTable, DateTable[jahr_woche] = SelectedWeek), 
        DateTable[Date]
    ) // Get the date corresponding to the selected week
VAR StartDate = 
    CALCULATE(
        MAX(DateTable[Date]),
        FILTER(
            DateTable, 
            DateTable[Date] <= SelectedDate &&
            DateTable[Date] > EDATE(SelectedDate, -6) // Get last 6 weeks
        )
    )
RETURN
    CALCULATE(
        SUM('YourFactTable'[YourValueColumn]), // Replace with your actual fact table and column
        FILTER(
            DateTable, 
            DateTable[Date] > EDATE(StartDate, -6) &&
            DateTable[Date] <= StartDate
        )
    )

If this helped, a Kudos 👍 or Solution mark would be great!🎉
Cheers,
Kedar Pande
Connect on LinkedIn

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.