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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Srinivas3350
Helper II
Helper II

Need a urgent help in DAX for YTD

Hello, I am using a measure which calculates YTD for previos year but the issue is  the measure is working fine but the YTD for last year is in 2023

 

Srinivas3350_0-1697020230265.png

as you can see in the above screenshot  the YTD for 2023 is 8705 if we calculate YTD for 2022 it is 8000 but the values are showing vice-versa can anyone help me what is the problem in DAX

this is the dax I used

 

YTD with Previous Years Sales =
VAR DataMaxDate =
    CALCULATE ( MAX ( 'Date Table'[Date] ), ALL ( 'Date Table'[Date] ) )
RETURN
    CALCULATE (
        [sum GBP],
        SAMEPERIODLASTYEAR (
            INTERSECT (
                VALUES ( 'Date Table'[Date] ),
                DATESYTD ( 'Date Table'[Date] )
            )
        )
    )
1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Srinivas3350 ,

According to your description, it seems that you’re trying to calculate the Year-to-Date (YTD) sales for the previous years. And it seems that the returned result is not correct base on current DAX formula. Please update the formula of measure [YTD with Previous Years Sales] as below and check if it can return the correct result...

YTD with Previous Years Sales =
VAR _Last =
    CALCULATE (
        LASTNONBLANK ( 'Date Table'[Date], [YTD] ),
        ALL ( 'Date Table'[Date] )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Date Table'[Date] ) <= _Last,
        CALCULATE ( [YTD], SAMEPERIODLASTYEAR ( 'Date Table'[Date] ) )
    )

If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Community Support Team _ Rena
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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Srinivas3350 ,

According to your description, it seems that you’re trying to calculate the Year-to-Date (YTD) sales for the previous years. And it seems that the returned result is not correct base on current DAX formula. Please update the formula of measure [YTD with Previous Years Sales] as below and check if it can return the correct result...

YTD with Previous Years Sales =
VAR _Last =
    CALCULATE (
        LASTNONBLANK ( 'Date Table'[Date], [YTD] ),
        ALL ( 'Date Table'[Date] )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Date Table'[Date] ) <= _Last,
        CALCULATE ( [YTD], SAMEPERIODLASTYEAR ( 'Date Table'[Date] ) )
    )

If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Srinivas3350
Helper II
Helper II

Sorry 2021 value is 8705

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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