Forum

Comparing not compl...
 
Notifications
Clear all

Comparing not completed months with DAX

4 Posts
2 Users
0 Reactions
57 Views
(@malcala)
Posts: 18
Eminent Member
Topic starter
 

Hy everyone,

I need to compare the Sales This Year with the Sales Previous Year. For this purpose I created the following measures:

This Year Sales:= SUM(Sales Amount)

Sales PY:= CALCULATE([Sales Amount], SAMEPERIODLASTYEAR('Dates Table'[Date]]

Now the problem is if I compare October 2020 to October 2019, I get This Year Sales for the Sales till the 26th of October and Sales PY is showing me the whole sales for October 2019. So I cannot compare this values. I will have the same problem by comparing YTD Data. (Today´s Date: 27.Oct 2020)

I searched on the Internet for some help and I found this Code but it is still not working:

[PY Last Day Selection]

:=

VAR

LastDaySelection =

    

LASTNONBLANK ( 'Date'[Date], [Sales Amount] )

VAR

CurrentRange =

    

DATESBETWEEN ( 'Date'[Date], MIN ( 'Date'[Date] ), LastDaySelection )

VAR

PreviousRange =

    

SAMEPERIODLASTYEAR ( CurrentRange )

RETURN
    

IF (

        

LastDaySelection >= MIN ( 'Date'[Date] ),

        

CALCULATE ( [Sales Amount], PreviousRange )

i should say that if I create a pivot which shows me the months I get the wrong numbers, that is the whole sales for October 2019 BUT if i use the field dates I get the correct results. It’s showing the sales till the 26th of October 2019 but as I said at the month level it is still showing the sum of the whole month. Do I have to use FILTER to alter the row context of the total sales for October 2019? 

 
Any Ideas how I get the desire result?? I appreciate your help
Regards,
 
Maria
ps: Unfortunately I cannot upload the file since it cointains some Company sensible data.

 
Posted : 28/10/2020 4:56 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Maria,

This part of the formula:

VAR

LastDaySelection =

    

LASTNONBLANK 'Date'[Date][Sales Amount] )

 

Should be referencing the dates in the Sales table, not the dates table. The dates table will have dates up to the end of the year. I hope that points you in the right direction.

In future, if you can't upload your actual file, please create a sample file to save me having to do so.

Thanks,

Mynda

 
Posted : 28/10/2020 7:41 pm
(@malcala)
Posts: 18
Eminent Member
Topic starter
 

Hi Mynda, 

sorry it took me too long to answer your post. I tried what you said but I still do not getting the numbers  I need. I attached a sample file. 

it might be some silly mistake I am doing again but I cannot understand right now what am I doing wrong. 

Thanks a lot for your help

Regards, 

Maria

 
Posted : 31/10/2020 4:56 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Maria,

The formula is calculating correctly. The last value in your sales table for 2020 is on 26th October, not 28th. Also, you can't look at that measure at the day level of detail because it will ignore 2019 dates where there are no values for those dates in 2020 e.g. 3rd October, 10th etc.

Mynda

 
Posted : 31/10/2020 8:02 pm
Share: