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
adieball
Helper I
Helper I

Sales previous Year to date

Hi

 

I've gone through literally hundreds of posts to find an answer for this, tried a myriad of suggestions, all end up in the same problem.

 

I have two measurements:

 

TotalSalesYTD

=CALCULATE(SUM(Invoice[NetPriceEuro]), DATESYTD(DateKey[Date]))

 

TotalSalesPreviousYTD

=CALCULATE(SUM(Invoice[NetPriceEuro]), SAMEPERIODLASTYEAR('DateKey'[Date]))

 

 

My Problem is that the TotalSalesPreviousYTD always shows the Total of the complete previous year and not the data from 01.01 of last year to todays date.

 

I have the same problem in PowerBI and PowerPivot

 

My DateKey table is continious, i.e. 01.01.13 - 31.12.2020

 

any help is highly appreciated

 

Thanks

1 ACCEPTED SOLUTION

Hi @adieball,


What I need:

 

Let's assume we did 100.000k€ in the complete last year (2016)

Today is the 31.10.17

I want a measure that shows me how much sales we have done last year (01.1.16 - 31.10.16)

 

I then need the same for previous year quester, etc. but the more "simple" SAMEPERIODLASTYEAR isn't working ...


Could you try the formula( without any time intelligence functions) below to see if it works in your scenario.  Smiley Happy

TotalSalesPreviousYTD =
CALCULATE (
    SUM ( Invoice[NetPriceEuro] ),
    FILTER (
        ALL ( Datekey ),
        'DateKey'[Date]
            >= DATE ( YEAR ( TODAY () ) - 1, 1, 1 )
            && 'DateKey'[Date] <= EDATE ( TODAY (), -12 )
    )
)

Regards

View solution in original post

13 REPLIES 13
v-ljerr-msft
Employee
Employee

Hi @adieball,

 

The formula below should also work. Smiley Happy

TotalSalesPreviousYTD =
CALCULATE (
    TOTALYTD ( SUM ( Invoice[NetPriceEuro] ), 'DateKey'[Date] ),
    SAMEPERIODLASTYEAR ( 'DateKey'[Date] )
)

Regards

Hi

 

nope, this also show the sum of the complate last year, ot the last year up to todays date.

 

Hi,

 

Share the link from where i can download your file.  Also, show the expected result there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi

 

sorry, can't share the file as it contains sensitive data.

 

What I need:

 

Let's assume we did 100.000k€ in the complete last year (2016)

Today is the 31.10.17

I want a measure that shows me how much sales we have done last year (01.1.16 - 31.10.16)

 

I then need the same for previous year quester, etc. but the more "simple" SAMEPERIODLASTYEAR isn't working ...

Hi @adieball,


What I need:

 

Let's assume we did 100.000k€ in the complete last year (2016)

Today is the 31.10.17

I want a measure that shows me how much sales we have done last year (01.1.16 - 31.10.16)

 

I then need the same for previous year quester, etc. but the more "simple" SAMEPERIODLASTYEAR isn't working ...


Could you try the formula( without any time intelligence functions) below to see if it works in your scenario.  Smiley Happy

TotalSalesPreviousYTD =
CALCULATE (
    SUM ( Invoice[NetPriceEuro] ),
    FILTER (
        ALL ( Datekey ),
        'DateKey'[Date]
            >= DATE ( YEAR ( TODAY () ) - 1, 1, 1 )
            && 'DateKey'[Date] <= EDATE ( TODAY (), -12 )
    )
)

Regards

Hi,

 

As long as months are dragged from the calendar table, my formula should work.  Dummy your dataset and share the download link.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

When having the months in the rows and the years in the column I see the data for the months and the TOTALYTD summary, everyhting looks good.

As soon as I drag the PreviousYTD (or any measurement using SAMEPERIODLASTYEAR) into thevalues, I get the error:

 

"Funktion 'SAMEPERIODLASTYEAR' only works with contiguous date selections" ......

 

 

Ashish_Mathur
Super User
Super User

Hi,

 

I am assuming that you have months in the visual as well.  What happens when you try this

 

=CALCULATE([TotalSalesYTD],SAMEPERIODLASTYEAR('DateKey'[Date]))

 

Does this work?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I have months as well (as quarter, weeks, etc).

Your formular also shows the complete sum of last year, not the sum of last year up to todays date (in last year)

MFelix
Super User
Super User

Hi @adieball,

 

Try this measure:

TotalSalesPreviousYTD =
TOTALYTD (
    SUM ( Invoice[NetPriceEuro] ),
    DATEADD ( 'DateKey'[Date], -1, YEAR )
)

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



I get the following error when trying to do so

 

Screen Shot 2017-10-27 at 16.51.07.png

 

 

 

 

 

 

 

 

 

 

 

Sorry for asking this but it appears to me in the print that between the -1 and year its not a comma.

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



You're right, on the screenshot it looks like a dot but it's actually a comma

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.