cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Day to day comparison against same period last year

I am trying to compare sales of each store with last year based on the currently selected period.  The issue here, there were no sales in this year and last year for certain days, What I am exactly looking for is to compare between dates that were available both in this year and last year.

 

I got the current year sales calculation working with the following formula but I cannot find a solution for the previous year sales total.

 

CY SALES = CALCULATE([Sales Amount],
            FILTER(CROSSJOIN(VALUES(DIM[STORE]),VALUES(CAL[DATE])),
               CALCULATE([Sales Amount],SAMEPERIODLASTYEAR(CAL[DATE]))>0
            )
           )

 

The amount for last year should be 261,057

 

https://1drv.ms/u/s!AmoScH5srsIYt0Fr8L-6r8HkFEI7

 

Sales.jpg

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted

Re: Day to day comparison against same period last year

Hi, this code should work. You can return CY, LY or delta (the number computed right now) by simply changing the RETURN part:

 

Diff = 
SUMX ( 
    SUMMARIZE ( 'FACT', 'CAL'[DATE], DIM[STORE] ),
    VAR SalesCY = [CY Sales Amount]
    VAR SalesLY = CALCULATE ( [CY Sales Amount], SAMEPERIODLASTYEAR( CAL[DATE] ) )
    RETURN
    IF ( 
        AND ( SalesCY > 0, SalesLY > 0 ),
        SalesCY - SalesLY
    )
)

It is not going to be a top-performer in terms of speed, but good enough for small data volumes.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

 

Alberto Ferrari - SQLBI

View solution in original post

Highlighted
Helper V
Helper V

Re: Day to day comparison against same period last year

Firstly, I should say that  It's my honor to have the question answered by Aberto Ferrari !

 

The solution worked perfectly, 

 

I was overly focusing on time intelligence and failed to make use of SUMX and variables. 

DAX is getting more interesting.

 

Thanks again!

 

 

View solution in original post

3 REPLIES 3
Highlighted
Helper V
Helper V

Sales of equivalent dates comparison

DataI am trying to compare sales of each store with last year based on the currently selected period.  The issue here, there were no sales in this year and last year for certain days, What I am exactly looking for is to compare between dates that were available both in this year and last year.

 

I got the current year sales calculation working with the following formula but I cannot find a solution for the previous year sales total.

 

CY TEST = CALCULATE([Sales Amount],
            FILTER(CROSSJOIN(VALUES(DIM[STORE]),VALUES(CAL[DATE])),
CALCULATE([Sales Amount],SAMEPERIODLASTYEAR(CAL[DATE]))>0
) )

 

Highlighted

Re: Day to day comparison against same period last year

Hi, this code should work. You can return CY, LY or delta (the number computed right now) by simply changing the RETURN part:

 

Diff = 
SUMX ( 
    SUMMARIZE ( 'FACT', 'CAL'[DATE], DIM[STORE] ),
    VAR SalesCY = [CY Sales Amount]
    VAR SalesLY = CALCULATE ( [CY Sales Amount], SAMEPERIODLASTYEAR( CAL[DATE] ) )
    RETURN
    IF ( 
        AND ( SalesCY > 0, SalesLY > 0 ),
        SalesCY - SalesLY
    )
)

It is not going to be a top-performer in terms of speed, but good enough for small data volumes.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

 

Alberto Ferrari - SQLBI

View solution in original post

Highlighted
Helper V
Helper V

Re: Day to day comparison against same period last year

Firstly, I should say that  It's my honor to have the question answered by Aberto Ferrari !

 

The solution worked perfectly, 

 

I was overly focusing on time intelligence and failed to make use of SUMX and variables. 

DAX is getting more interesting.

 

Thanks again!

 

 

View solution in original post

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors