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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
anilpoda
Frequent Visitor

DAX Query for Current Year vs Previous Year Weekly Sales

I am trying to create a table visualization with 3 columns 

1. Week No

2. Current Year Weekly Sales

3. Previous Year Weekly Sales

 

I have a Date Table with Calendar Year and Week No Columns. Whenever I select an year in the dropdown filter I should see selected Year Week No, Selected Year weekly sales in one column and previous year weekly sales. Can anyone help me with the DAX query please?

 

I don't have the option to attach Pbix file. Kindly download the report I am working using below link

 

Download Pbix File 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @anilpoda ,

 

According to your description, here are my steps you can follow as a solution.

(1)  My test data is the same as yours.

(2) We can create two measures.

Current Year Weekly Sales =
CALCULATE (
    SUM ( Fact_OrderLines[Value] ),
    FILTER (
        ALL ( Fact_OrderLines ),
        YEAR ( [Order Date] ) = MAX ( 'Date'[Calendar Year] )
            && WEEKNUM ( Fact_OrderLines[Order Date] ) = MAX ( 'Date'[Week No] )
    )
)
Previous Year Weekly Sales =
CALCULATE (
    SUM ( Fact_OrderLines[Value] ),
    FILTER (
        ALL ( Fact_OrderLines ),
        YEAR ( [Order Date] )
            = MAX ( 'Date'[Calendar Year] ) - 1
            && WEEKNUM ( Fact_OrderLines[Order Date] ) = MAX ( 'Date'[Week No] )
    )
)

 (3) Then the result is as follows.

vtangjiemsft_0-1673858098843.png

Best Regards,

Neeko Tang

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

Hi @anilpoda ,

 

According to your description, here are my steps you can follow as a solution.

(1)  My test data is the same as yours.

(2) We can create two measures.

Current Year Weekly Sales =
CALCULATE (
    SUM ( Fact_OrderLines[Value] ),
    FILTER (
        ALL ( Fact_OrderLines ),
        YEAR ( [Order Date] ) = MAX ( 'Date'[Calendar Year] )
            && WEEKNUM ( Fact_OrderLines[Order Date] ) = MAX ( 'Date'[Week No] )
    )
)
Previous Year Weekly Sales =
CALCULATE (
    SUM ( Fact_OrderLines[Value] ),
    FILTER (
        ALL ( Fact_OrderLines ),
        YEAR ( [Order Date] )
            = MAX ( 'Date'[Calendar Year] ) - 1
            && WEEKNUM ( Fact_OrderLines[Order Date] ) = MAX ( 'Date'[Week No] )
    )
)

 (3) Then the result is as follows.

vtangjiemsft_0-1673858098843.png

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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