Forum Discussion

rajasekar_o's avatar
rajasekar_o
Icon for Helper V rankHelper V
1 year ago
Solved

lymtd calculate

I have sales data from  1-1-2022 to 25-09-2024 Sales Table  have the column invno,invdate,item,qty,Netamount i have calender table  start date :1-1-2024end date: 31-12-2024 AND MTD calculatio...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi rajasekar_o 

     

    Thanks for the reply from Kedar_Pande  and Ashish_Mathur .

     

    Do you need to show the sum for the same time period last year if you select YEAR and MONTH, and the value for the current month of last year if you don't? If I understand correctly, the following test is for your reference:

     

    My sample:

    Calendar table:

     

    Sales table:

     

    Create a measure as follow:

    LMTD = 
    VAR _year = SELECTEDVALUE('Calendar'[YEAR])
    RETURN
    IF(
        ISFILTERED('Calendar'[YEAR]) && ISFILTERED('Calendar'[month]), 
        CALCULATE(SUM(sales[Amount]), FILTER(sales, YEAR([Inv Date]) = _year - 1 && [Inv Date].[Month] IN VALUES('Calendar'[month]))),
        CALCULATE(SUM(sales[Amount]), FILTER(sales, YEAR([Inv Date]) = _year - 1 && MONTH([Inv Date]) = MONTH(TODAY())))
    )

     

    Output:

     

     

    After my testing, if you use SAMEPERIODLASTYEAR, this requires that you have the same period of last year in your calendar table, like the screenshots below:

     

    When the same date last year does not exist in the calendar table:

     

    When the same date last year exists in the calendar table:

     

    Best Regards,
    Yulia Xu

     

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