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 calculation is 

MTD Sale _new =
VAR _year = VALUES('date'[Year])
VAR _month = VALUES('date'[month no])
RETURN
IF(
    ISFILTERED('date'[Year]) && ISFILTERED('date'[month no]),
    CALCULATE(
        SUM('sales'[Amount]),
        FILTER(
            'Sales',
            YEAR('sales'[Inv Date]) in _year
            &&
            MONTH('sales'[Inv Date]) IN _month
        )
    ),
    TOTALMTD(
        SUM('sales'[Amount]),
        'sales'[Inv Date]
    )
)
now i want to calculate LY MTD SALES 
IF i didn't filter any month it need to show Curent month of  LYMTD 
IF I select any multiple month it need to show that selected month savel value
i try CALCULATE LYMTD : 
CALCULATE([MTD Sale _new],
    SAMEPERIODLASTYEAR('Date'[Date])
)
 ITS NOT working.
  • 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.

8 Replies

  • Create a new measure for LY MTD sales:

    LY MTD Sale =
    VAR _year = VALUES('Date'[Year])
    VAR _month = VALUES('Date'[Month No])
    RETURN
    IF(
    ISFILTERED('Date'[Year]) && ISFILTERED('Date'[Month No]),
    CALCULATE(
    SUM('Sales'[Net Amount]),
    FILTER(
    'Sales',
    YEAR('Sales'[Inv Date]) = _year - 1 && // Adjust year for LY
    MONTH('Sales'[Inv Date]) IN _month
    )
    ),
    TOTALMTD(
    SUM('Sales'[Net Amount]),
    SAMEPERIODLASTYEAR('Date'[Date])
    )
    )
  • Hi,

    Share some data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rajasekar_o 

     

    Can these current methods solve your problem? If yes, could you please mark them as solutions? This will help more users who are facing the same or similar difficulties. Thank you!

     

    Best Regards,
    Yulia Xu