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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Fowmy
Super User
Super User

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

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

2 ACCEPTED SOLUTIONS

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

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!

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3

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

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!

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Fowmy
Super User
Super User

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
) )

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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