Forum Discussion

mith_tina's avatar
mith_tina
Frequent Visitor
4 years ago
Solved

Total YTD

hi,

in my data set Order date is upto December 2022. i wanted to show last year YTD and this year YTD upto july . but when i try to create dax , it is showing correctly last year data but this year it is showing total of all  upto december where i wanted to show only this year ytd upto july. i have created date table and connect with order date. 

 

how can i write the dax for ytd? 

 

Thanks in advance.

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi mith_tina ,

     

    Try this measure and use [Year] as the axis, this should return the correct result.

    Total YTD =
    VAR _date =
        EOMONTH ( TODAY (), -1 )
    VAR _year =
        MAX ( 'Calendar'[Year] )
    VAR _month =
        MONTH ( _date )
    VAR _day =
        DAY ( _date )
    VAR _total =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Calendar',
                'Calendar'[Date] >= DATE ( _year, 1, 1 )
                    && 'Calendar'[Date] <= DATE ( _year, _month, _day )
            )
        )
    RETURN
        _total

    The PBIX file is attached for reference.

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi mith_tina ,

     

    Try this measure and use [Year] as the axis, this should return the correct result.

    Total YTD =
    VAR _date =
        EOMONTH ( TODAY (), -1 )
    VAR _year =
        MAX ( 'Calendar'[Year] )
    VAR _month =
        MONTH ( _date )
    VAR _day =
        DAY ( _date )
    VAR _total =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Calendar',
                'Calendar'[Date] >= DATE ( _year, 1, 1 )
                    && 'Calendar'[Date] <= DATE ( _year, _month, _day )
            )
        )
    RETURN
        _total

    The PBIX file is attached for reference.

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

  • SpartaBI's avatar
    SpartaBI
    Community Champion

    mith_tina is your calendar table have full years for all the relvant years?
    Are you using the calendar table date column in your total ytd measure?

    • mith_tina's avatar
      mith_tina
      Frequent Visitor

      yes my calender table have full years and i am using my calender table date column.