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
Lewis_S_William
Frequent Visitor

Previous Year To Date

Hi

 

I've asked the question before and it got solved. I'm not replicating the solutions and I can't get it to work.

 

I have a sales table with sales recorded from 01/01/2022 to 01/04/2023. I've created a data table with the same range and created a relation between the 2.

 

I can pull off current year sales not a problem. When I try to create previous year sales it's totalling the full month of april last year as well when it should be 01/01/2022..01/04/2022

 

Lewis_S_William_0-1706546762076.png

 

It should be 84k but it's returning 120k.

 

I've tried the following

 

 
Sales PY (£) =
    CALCULATE(SUM(SalesDashboard[SalesAmountActual]),SAMEPERIODLASTYEAR('Date'[Date]))
YTD LY (limited by last date in Data table) =
VAR DataMaxDate =
    CALCULATE ( MAX ( 'Date'[Date] ), ALL ( SalesDashboard ) )
RETURN
    CALCULATE (
        [YTD],
        SAMEPERIODLASTYEAR (
            INTERSECT (
                VALUES ( 'Date'[Date] ),
                DATESBETWEEN ( 'Date'[Date], BLANK (), DataMaxDate )
            )
        )
    )

Any suggestions?

2 REPLIES 2
Greg_Deckler
Super User
Super User

@Lewis_S_William Try Better Year to Date: Better Year to Date Total - Microsoft Fabric Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Daniel29195
Super User
Super User

@Lewis_S_William 

Please try this modified version : 


YTD LY (limited by last date in Data table) =
VAR DataMaxDate =
    CALCULATE ( MAX ( 'Date'[Date] ), ALL ( SalesDashboard ) )
RETURN
    CALCULATE (
        [YTD],
        SAMEPERIODLASTYEAR (datesytd('Date'[Date])), all(dimdate[Date])
)
        
   

 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !

It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

 

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.