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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply

Prior YTD formula not working

When I do a standard YTD it is working as it should. However, when I try to do a Prior Year YTD it is giving me the value of the entire year vs the same YTD period.

 

YTD is showing data from 1/1/24 to 1/8/24. I need the Prior Year YTD to show 1/1/23 to 1/8/23 for example.

 

I have tried about 1000 different formulas but here is my most recent that I got by using Copilot within Power BI

 

 

//PY YTD = CALCULATE(

    SUM('vCorporateGandA'[Amount]),

    SAMEPERIODLASTYEAR(

        'CalendarTable'[Date].[Date]

    )

)

 

I'm getting $31.64M with this formula. When I filter by last year, date, etc manually get $2.37M.

 

I'm needing to put this in a table to compare multiple different values so I can't filter manually.

3 ACCEPTED SOLUTIONS
bchager6
Super User
Super User

@brittanyruffin  Check out @wdx223_Daniel 's solution here. It works.

PY YTD = 
VAR _END = MAX(CalendarTable[Date])
VAR _START = DATE(YEAR(_END), MONTH(_END), 1)
RETURN CALCULATE(SUM('vCorporateGandA'[Amount], SAMEPERIODLASTYEAR(DATESMTD(CalendarTable[Date])),CalendarTable[Date]<=EDATE(_END,-12))


https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SAMEPERIODLASTYEAR-return-a-wrong-re...

View solution in original post

danextian
Super User
Super User

Hi @brittanyruffin ,

 

SAMEPERIODLASTYEAR calculates the value in the same period last year relative to the current row. It does not calcualted YTD.  Here are sample formulas  =

sum ytd = 
CALCULATE ( [Sum of Values], DATESYTD ( Dates[Date] ) )
sum ytd py = 
CALCULATE ( [sum ytd], SAMEPERIODLASTYEAR ( Dates[Date] ) )

danextian_0-1704781380343.png

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

v-xuxinyi-msft
Community Support
Community Support

Hi @brittanyruffin 

 

My sample:

vxuxinyimsft_0-1704872004659.png

 

You can create a measure as follows.

Measure 2 = 
VAR _startdate = DATEVALUE(DATE(2024, 1, 1))
RETURN
IF( 
    YEAR(SELECTEDVALUE('vCorporateGandA'[Date])) = YEAR(TODAY()) - 1 
    && MONTH(SELECTEDVALUE('vCorporateGandA'[Date])) <= MONTH(_startdate) 
    && MONTH(SELECTEDVALUE('vCorporateGandA'[Date])) <= MONTH(TODAY()) 
    && DAY(SELECTEDVALUE('vCorporateGandA'[Date])) >= DAY(_startdate) && DAY(SELECTEDVALUE('vCorporateGandA'[Date])) <= DAY(TODAY()), 
    1, 
    0
)

 

Prior Year YTD = CALCULATE(SUM('vCorporateGandA'[value]), FILTER( ALLEXCEPT('vCorporateGandA', 'vCorporateGandA'[id]), [Measure 2] = 1))

 

vxuxinyimsft_1-1704872096737.png

Is this the result you expect?

 

If I've misunderstood you, please provide detailed sample data and the results you are hoping for: How to provide sample data in the Power BI Forum - Microsoft Fabric Community. Please remove any sensitive data in advance.

 

Best Regards,

Community Support Team _Yuliax

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
v-xuxinyi-msft
Community Support
Community Support

Hi @brittanyruffin 

 

My sample:

vxuxinyimsft_0-1704872004659.png

 

You can create a measure as follows.

Measure 2 = 
VAR _startdate = DATEVALUE(DATE(2024, 1, 1))
RETURN
IF( 
    YEAR(SELECTEDVALUE('vCorporateGandA'[Date])) = YEAR(TODAY()) - 1 
    && MONTH(SELECTEDVALUE('vCorporateGandA'[Date])) <= MONTH(_startdate) 
    && MONTH(SELECTEDVALUE('vCorporateGandA'[Date])) <= MONTH(TODAY()) 
    && DAY(SELECTEDVALUE('vCorporateGandA'[Date])) >= DAY(_startdate) && DAY(SELECTEDVALUE('vCorporateGandA'[Date])) <= DAY(TODAY()), 
    1, 
    0
)

 

Prior Year YTD = CALCULATE(SUM('vCorporateGandA'[value]), FILTER( ALLEXCEPT('vCorporateGandA', 'vCorporateGandA'[id]), [Measure 2] = 1))

 

vxuxinyimsft_1-1704872096737.png

Is this the result you expect?

 

If I've misunderstood you, please provide detailed sample data and the results you are hoping for: How to provide sample data in the Power BI Forum - Microsoft Fabric Community. Please remove any sensitive data in advance.

 

Best Regards,

Community Support Team _Yuliax

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

danextian
Super User
Super User

Hi @brittanyruffin ,

 

SAMEPERIODLASTYEAR calculates the value in the same period last year relative to the current row. It does not calcualted YTD.  Here are sample formulas  =

sum ytd = 
CALCULATE ( [Sum of Values], DATESYTD ( Dates[Date] ) )
sum ytd py = 
CALCULATE ( [sum ytd], SAMEPERIODLASTYEAR ( Dates[Date] ) )

danextian_0-1704781380343.png

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

thank you! this worked exactly how i needed.

 

do you also know how i can get a Prior Year calculation for the current quarter?

i have this formula that gives me the current quarter amount without me having to change my filters each quarter on the visual.

 

Current Quarter Amount =
CALCULATE(
    SUM('vCorporateGandA'[Amount]),
    YEAR('CalendarTable'[Date]) = YEAR(TODAY()) &&
    QUARTER('CalendarTable'[Date]) = QUARTER(TODAY())
)

 

i'm needing this formula to show the prior year. i tried doing something similar to what you had above with but it did not work:

CALCULATE([Current Quarter Amount], SAMEPERIODLASTYEAR(Dates[Date]))

 

Any ideas?

thank you! this worked exactly how i needed.

 

do you also know how i can get a Prior Year calculation for the current quarter?

i have this formula that gives me the current quarter amount without me having to change my filters each quarter on the visual.

 

Current Quarter Amount =
CALCULATE(
    SUM('vCorporateGandA'[Amount]),
    YEAR('CalendarTable'[Date]) = YEAR(TODAY()) &&
    QUARTER('CalendarTable'[Date]) = QUARTER(TODAY())
)

 

i'm needing this formula to show the prior year. i tried doing something similar to what you had above with but it did not work:

CALCULATE([Current Quarter Amount], SAMEPERIODLASTYEAR(Dates[Date]))

 

Any ideas?

bchager6
Super User
Super User

@brittanyruffin  Check out @wdx223_Daniel 's solution here. It works.

PY YTD = 
VAR _END = MAX(CalendarTable[Date])
VAR _START = DATE(YEAR(_END), MONTH(_END), 1)
RETURN CALCULATE(SUM('vCorporateGandA'[Amount], SAMEPERIODLASTYEAR(DATESMTD(CalendarTable[Date])),CalendarTable[Date]<=EDATE(_END,-12))


https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SAMEPERIODLASTYEAR-return-a-wrong-re...

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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