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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jayjay0306
Helper III
Helper III

DAX - sales previous week based on filter

Hi people,

I need some help here on what - at least appears to be - a simple task:

I need to make a DAX measure showing the sales last week and the week before, based on the weeknumber I choose in the "week"-filter in the report.

Now, I have tried to make the following Dax (as you can see I have an attribute ("CALENDAR_PREVIOUS_WEEK") in my calendar table showing previous week, which I am trying to use, but I am not sure I can use it due to the filter requirement):

Sale prev. week = CALCULATE(SUM('KPI Sell Out'[Sales Out Packs CY]),'Calendar'[CALENDAR_PREVIOUS_WEEK],filter('Calendar',YEAR('Calendar'[Date])=Year(TODAY())))

 But the  result is not correct. (below)

One issue is to "overrule" the filter showing one week, where we need to see the previous week (which is basically out of range of the week chosen in filtter).

Capture11.PNG

 

If anyone have a solution, it will be greatly appreciated.

thanks.

Br,

JayJay0306

 

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

Hi @jayjay0306 ,

 

This is my test table:

vyadongfmsft_0-1669258688698.png

 

Calendar table:

vyadongfmsft_1-1669258717404.png

 

Relationship:

vyadongfmsft_2-1669258756962.png

 

Create a measure:

sales previous week =
VAR current_week =
    SELECTEDVALUE ( 'CalendarTable'[Current_Week] )
VAR previous_week = current_week - 1
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALL ( 'CalendarTable' ),
            'CalendarTable'[Current_Week] = previous_week
                && YEAR ( 'CalendarTable'[Date] ) = YEAR ( TODAY () )
        )
    )

 

I think you will get the result you want:

vyadongfmsft_3-1669258893197.png

Best regards,

Yadong Fang

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

1 REPLY 1
v-yadongf-msft
Community Support
Community Support

Hi @jayjay0306 ,

 

This is my test table:

vyadongfmsft_0-1669258688698.png

 

Calendar table:

vyadongfmsft_1-1669258717404.png

 

Relationship:

vyadongfmsft_2-1669258756962.png

 

Create a measure:

sales previous week =
VAR current_week =
    SELECTEDVALUE ( 'CalendarTable'[Current_Week] )
VAR previous_week = current_week - 1
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALL ( 'CalendarTable' ),
            'CalendarTable'[Current_Week] = previous_week
                && YEAR ( 'CalendarTable'[Date] ) = YEAR ( TODAY () )
        )
    )

 

I think you will get the result you want:

vyadongfmsft_3-1669258893197.png

Best regards,

Yadong Fang

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

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.