Forum Discussion

SivaReddy's avatar
SivaReddy
Frequent Visitor
5 years ago
Solved

TOTALYTD is not working

I loaded factinternetsales from adventureworks2016 database into powerbi. created totalytd column using following dax formula.

 

TOTALYTD= TOTALYTD(sum(FactInternetSales[SalesAmount]),FactInternetSales[OrderDate].[Date])

 

the above dax is not working. please find the below screenshot.

 

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi SivaReddy ,

     

    Try this formula.

    Measure = CALCULATE(SUM('Table'[sales]),FILTER(ALLSELECTED('Table'),YEAR('Table'[date])=YEAR(SELECTEDVALUE('Table'[date]))&&'Table'[date]<=MAX('Table'[date])))

     

    Best Regards,

    Jay

4 Replies

  • Samarth_18's avatar
    Samarth_18
    Icon for Community Champion rankCommunity Champion

    Hi SivaReddy ,

    If you have calender table/date table which connected to FactInternetSales table  then pass date column from calender/date table into totalytd function.

    TOTALYTD ( SUM ( FactInternetSales[SalesAmount] ), Calender_table[Date] )

    or you can try below code:-

    TOTALYTD =
    CALCULATE (
        SUM ( FactInternetSales[SalesAmount] ),
        YEAR ( FactInternetSales[OrderDate] ) = YEAR ( NOW () )
    )

     

    Thanks, 

    Samarth

     

    • SivaReddy's avatar
      SivaReddy
      Frequent Visitor

      I used fulldatealternativekey of dimdate. Still I am not getting ytd. please find the below screenshot.

       

      dax formula used is TotalYTD = TOTALYTD(sum(FactInternetSales[SalesAmount]),DimDate[FullDateAlternateKey].[Date])

      • Samarth_18's avatar
        Samarth_18
        Icon for Community Champion rankCommunity Champion

        What about below code?

         

        TOTALYTD =
        CALCULATE (
            SUM ( FactInternetSales[SalesAmount] ),
            YEAR ( FactInternetSales[OrderDate] ) = YEAR ( NOW () )
        )

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi SivaReddy ,

     

    Try this formula.

    Measure = CALCULATE(SUM('Table'[sales]),FILTER(ALLSELECTED('Table'),YEAR('Table'[date])=YEAR(SELECTEDVALUE('Table'[date]))&&'Table'[date]<=MAX('Table'[date])))

     

    Best Regards,

    Jay