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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
joshua1990
Post Prodigy
Post Prodigy

Show last 5 weeks based on selected week

Hi community!

I have a table that shows the sales pro each product per date. THen I have a calendar table linked to that table to aggegrate the data into weekly buckets.

Now I would like to show in a pivot table the last 5 weeks sales in thos format

Selected Week2024-012024-022024-032024-042024-052024-06
0156891 
02 68912
03  8912

 

It is like a waterfall, showing the last 5 weeks sales based on the selected week.

 

How would you build that?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1708865865864.png

 

 

Jihwan_Kim_0-1708865845676.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Expected result measure: = 
VAR _selectedyearweek =
    MAX ( 'Axis table'[weekenddate] )
VAR _t =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        FILTER (
            ALL ( 'Calendar'[Year-Week], 'Calendar'[weekenddate] ),
            'Calendar'[weekenddate] >= _selectedyearweek
        ),
        ORDERBY ( 'Calendar'[weekenddate], ASC )
    )
RETURN
    CALCULATE ( SUM ( Sales[Sales] ), KEEPFILTERS ( _t ) )

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1708865865864.png

 

 

Jihwan_Kim_0-1708865845676.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Expected result measure: = 
VAR _selectedyearweek =
    MAX ( 'Axis table'[weekenddate] )
VAR _t =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        FILTER (
            ALL ( 'Calendar'[Year-Week], 'Calendar'[weekenddate] ),
            'Calendar'[weekenddate] >= _selectedyearweek
        ),
        ORDERBY ( 'Calendar'[weekenddate], ASC )
    )
RETURN
    CALCULATE ( SUM ( Sales[Sales] ), KEEPFILTERS ( _t ) )

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.