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
heathernicole
Continued Contributor
Continued Contributor

SAMPLEPERIODLASTYEAR pulling FULL year - not previous YTD

I am trying to compare YTD sales to Previous YTD sales. 

 

YTD formula:

 

SalesYTD = 
CALCULATE (
[Incoming Total Sales], 
FILTER (
ALL ( 'Calendar - Transaction Date' ), 
'Calendar - Transaction Date'[Transaction Date Year Number] = MAX ( 'Calendar - Transaction Date'[Transaction Date Year Number] )
&& 'Calendar - Transaction Date'[Transaction Date] <= MAX ( 'Calendar - Transaction Date'[Transaction Date])
)
)
PYTD Sales = 
CALCULATE (
    [Incoming Total Sales], 
    FILTER (
        ALL ( 'Calendar - Transaction Date' ), 
        'Calendar - Transaction Date'[Transaction Date Year Number] = (MAX ( 'Calendar - Transaction Date'[Transaction Date Year Number]) -1)
            && 'Calendar - Transaction Date'[Transaction Date] <= MAX ( 'Calendar - Transaction Date'[PY Date])
    )
)

However - the PYTD measure (no matter what variation I do) is pulling the FULL year for last year

 

Even using SAMPLEPERIODLASTYEAR. I can NOT figure out why it's doing that rather than pulling JUST the data for YTD LAST year. 

Previous Year Sales (Incoming) = CALCULATE([Incoming Total Sales], SAMEPERIODLASTYEAR('Calendar - Transaction Date'[Transaction Date]))

ANY ideas as to WHY it's behaving this way? It's the same on EVERY report I have. 

~heathernicoale
1 ACCEPTED SOLUTION

https://community.powerbi.com/t5/Desktop/Prior-year-year-to-date-sales/m-p/173509#M75776 

 

So the solution from this forum question did the trick perfectly... it doesn't quite answer why the other methods didn't work - but for now, it gives the data I need.

 

here's the formula modified; it's quite a bear of a formula: lol 

 

PYTD Sales = 
CALCULATE(
[Incoming Total Sales],
SAMEPERIODLASTYEAR(
DATESYTD('Calendar - Transaction Date'[Transaction Date])
),
FILTER(
ALL('Calendar - Transaction Date'),
'Calendar - Transaction Date'[Transaction Date Month Number] <= (MONTH(NOW())-1)
)
)+
CALCULATE(
[Incoming Total Sales],
SAMEPERIODLASTYEAR(
DATESYTD('Calendar - Transaction Date'[Transaction Date])
),
FILTER(
ALL('Calendar - Transaction Date'),
'Calendar - Transaction Date'[Transaction Date Month Number] = MONTH(NOW())
&& 'Calendar - Transaction Date'[Transaction Date Day Number] <= DAY(NOW())
)
)
~heathernicoale

View solution in original post

10 REPLIES 10
SivaMani
Resident Rockstar
Resident Rockstar

@heathernicole,

 

Why don't you try this formula,

 

YTD = TOTALYTD(SUM([Income Total Sales]),'Calendar - Transaction Date')

 

PYTD = CALCULATE([YTD],SAMEPERIODLASTYEAR('Calendar - Transaction Date') )

@SivaMani - thanks for your input, first off. 🙂 

 

Here are the results - I've tried this variation before and I get the same results no matter what. 

 

PYTD2.PNG

~heathernicoale

Hi @heathernicole

 

Give this a shot. In PYTD sales MEASURE

 

Replace

MAX ( 'Calendar - Transaction Date'[PY Date])

 

With

 

If(HASONEVALUE(
'Calendar - Transaction Date'[Date]),
DATEADD(values('Calendar - Transaction Date'[Date]),-1,YEAR))

 

 


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad - Thank you for your help! 🙂 

 

It only produced a blank value. 😞 

 

PYTD3.PNG

~heathernicoale

@heathernicole do you have calendar/date dimension in your model? If not you need one, and then it will be easier to work with.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k - I do! That's why I'm not sure why it's having so many problems...

 

CY Table.PNG

 

~heathernicoale

https://community.powerbi.com/t5/Desktop/Prior-year-year-to-date-sales/m-p/173509#M75776 

 

So the solution from this forum question did the trick perfectly... it doesn't quite answer why the other methods didn't work - but for now, it gives the data I need.

 

here's the formula modified; it's quite a bear of a formula: lol 

 

PYTD Sales = 
CALCULATE(
[Incoming Total Sales],
SAMEPERIODLASTYEAR(
DATESYTD('Calendar - Transaction Date'[Transaction Date])
),
FILTER(
ALL('Calendar - Transaction Date'),
'Calendar - Transaction Date'[Transaction Date Month Number] <= (MONTH(NOW())-1)
)
)+
CALCULATE(
[Incoming Total Sales],
SAMEPERIODLASTYEAR(
DATESYTD('Calendar - Transaction Date'[Transaction Date])
),
FILTER(
ALL('Calendar - Transaction Date'),
'Calendar - Transaction Date'[Transaction Date Month Number] = MONTH(NOW())
&& 'Calendar - Transaction Date'[Transaction Date Day Number] <= DAY(NOW())
)
)
~heathernicoale

@heathernicole thanks for sharing, it seems way too much for a simple calclulation and i did it many times in the past with similar fomulas proposed to your earlier and it worked fine, something we are surely missing in your data model.

 

Anyhow, atleast you can move on and get back to this when you have time. 🙂



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k - That's what I thought - I'm not sure what I'm missing in the data model either, but for now it will work. 🙂 

 

Thanks for your help!

Also, @Zubair_Muhammad @SivaMani 

~heathernicoale

@heathernicole it suppose to solve the problem. Interesting, it should work.

 

Can you share pick of relationship model, anything weird there.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.