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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Microsoft Employee
Microsoft 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.