Forum Discussion

Thalbish's avatar
Thalbish
Frequent Visitor
1 year ago
Solved

Last Year Sales Giving In-correct output

  I have a date table created with the formula `Date = CALENDAR(MIN('RetailTransactions'[BusinessDate]), TODAY())`, which is connected to my sales table through a one-to-many relationship. When I ca...
  • Kedar_Pande's avatar
    1 year ago

    Instead of using SAMEPERIODLASTYEAR, which returns the entire month when a larger date range is selected, you can use the DATEADD function to get last year's sales while maintaining the context of the selected dates.

     

    Total Sales Line Last Year =
    ABS(
    CALCULATE(
    SUM(RetailTransactionSalesLines[NetAmount]),
    DATEADD('Date'[Date], -1, YEAR)
    )
    )

    Last Year Month-to-Date (MTD)

    LY MTD Sales =
    ABS(
    CALCULATE(
    SUM(RetailTransactionSalesLines[NetAmount]),
    DATESMTD(DATEADD('Date'[Date], -1, YEAR))
    )
    )

     Last Year Year-to-Date (YTD)

    LY YTD Sales =
    ABS(
    CALCULATE(
    SUM(RetailTransactionSalesLines[NetAmount]),
    DATESYTD(DATEADD('Date'[Date], -1, YEAR))
    )
    )

     

    Your Kudos/Likes are much appreciated!
    If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
    Regards,
    Kedar Pande
    www.linkedin.com/in/kedar-pande

  • Anonymous's avatar
    Anonymous
    1 year ago

    Thank you DataNinja777 , dharmendars007 and Kedar_Pande ,Your insights are very good. Here are some additional points.

    Hi, Thalbish 

    I think you can refer to the daxpatterns article related to dates, which describes in detail how to use the date table to calculate MTD, YTD, PMTD, PYTD:

    Week-related calculations – DAX Patterns

    MTD:

    YTD:

    PYTD:

     

     

     

    How to Get Your Question Answered Quickly

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

    Best Regards

    Jianpeng Li

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