Forum Discussion
anilpoda
3 years agoFrequent 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. Wh...
- Anonymous3 years ago
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.
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.
Anonymous
3 years agoNot 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.
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.