cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper I

## PY Sales Actually Pull Exact Same Period Last Year

Hi there,

The below DAX Function is the function for same period last year, but I only want to see the values up to the March 30th of last year. I want to see the exact same time frame YOY and I would like my data to populate automatically as the days progress throughout the year. Please see measure below. PBI is saying that I have too few arguments for DatesBetween.

SamePeriodLastYear =
CALCULATE(
[Net Sales],
SAMEPERIODLASTYEAR(
DATESBETWEEN(
FILTER(
ALLSELECTED(FactNetSales),
FactNetSales[Posting Date]< TODAY()))))

4 REPLIES 4
Super User

Sample period last year and Trailing measure with Date dimension will work, for that, you need to make some date is selected on the page

``````Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

``````

or try like

``````YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"),'Date'[Date]<=today())

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"),'Date'[Date]<=date(year(today()-1),month(today()),day(today()))``````
Helper I

I'm sorry, no this did not work.

However, I attempted another measure like this but now I am experiencing missing data since there were no sales on certain dates this year in 2020.  All I want is my data to stop on the current day (today) (max day). For example if today was March 25th 2020 then all I would want to pull is Prior Year Jan 1 2019 to March 25 2019. The exact same time period. I would not want to pull entire month or year. Just pull net sales up current date. Below is the formula I used and the missing data

SamePeriodLatYear =
VAR MaxDate = EDATE(CALCULATE(MAX('FactNetSales'[Posting Date]),ALL(FactNetSales)),-12)
RETURN
CALCULATE(
[Net Sales],
FILTER(SAMEPERIODLASTYEAR('DimCalendar'[DateKey]),'DimCalendar'[DateKey]<= MaxDate
))

Community Support

Hi @LyncoData1 ,

``````SamePeriodLatYear =
VAR tod =
TODAY ()
VAR lastyear =
DATE ( YEAR ( tod ) - 1, MONTH ( tod ), DAY ( tod ) )
VAR firstday =
DATE ( YEAR ( tod ) - 1, 1, 1 )
RETURN
CALCULATE (
[Net Sales],
FILTER (
ALL ( 'DimCalendar' ),
'DimCalendar'[DateKey] <= lasytear
&& 'DimCalendar'[DateKey] >= firstday
)
)
``````

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Helper I

This did not work. However, I did use the two measures below that gave me what I wanted for Net Sales. However, now I need help with finding YTD MTD Sales based on the measures listed below to ensure they fall into the current "TODAY" time frame. Would you have any insight ?

Actual SamePeriodLastYear =
CALCULATE (
[Net Sales],
FILTER ( 'DimCalendar', 'DimCalendar'[Month] <= MONTH( ( TODAY () ) )
))

Actual SamePeriodLastYear1 =
CALCULATE([Actual SamePeriodLastYear],(SAMEPERIODLASTYEAR('DimCalendar'[DateKey])) )

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.