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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
LyncoData1
Helper I
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
amitchandak
Super User
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()))
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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
))
 
 
 

March.PNG

Hi @LyncoData1 ,

Please try this one.

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
        )
    )

 

If it doesn't meet your requirement,  kindly share your sample data and excepted result to me if you don't have any Confidential Information. Please upload your files to One Drive for Business and share the link here.

 

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

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])) )
 
PY.PNG

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.