Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
rajasekar_o
Helper V
Helper V

LY MTD Calculation

Hi team,
i want to calculate LYMTD

Used Measure
LY MTD Sales =
VAR CurrentDate = MAX('date'[Date])
VAR PreviousYearDate = EDATE(CurrentDate, -12)
RETURN
CALCULATE(
    [sales amount],
    FILTER(
        ALL('date'),
        'date'[Date] <= CurrentDate &&                  
        'date'[Date] <= PreviousYearDate &&            
        'date'[Date] >= DATE(YEAR(CurrentDate)-1, MONTH(CurrentDate), 1)
    )
)
 
 

rajasekar_o_0-1727955442406.png

 

if i select any item IN FILTER 
LYMTD  showing blank
rajasekar_o_1-1727955687309.png

 





1 ACCEPTED SOLUTION
v-yaningy-msft
Community Support
Community Support

Hi, @rajasekar_o 

Thanks for Kedar_Pande, Greg_Deckler and bhanu_gautam replies. Are you currently addressing this issue? If not, you can refer to the following dax.

vyaningymsft_0-1729669395004.png

 

LY MTD Sales = 
VAR _currentDate = MAX('Table 2'[Inv Date])
VAR _previousYearDate = EDATE(_currentDate, -12)
VAR _item = SELECTEDVALUE('Table 2'[Item])
RETURN
CALCULATE(
    SUM('Table 2'[Amount]),
    FILTER(
        ALL('Table 2'),
        'Table 2'[Inv Date] <= _currentDate &&                  
        'Table 2'[Inv Date] >= _previousYearDate &&
        'Table 2'[Item] = _item
    )
)

 

Best Regards,
Yang

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 in the Power BI Forum

View solution in original post

6 REPLIES 6
v-yaningy-msft
Community Support
Community Support

Hi, @rajasekar_o 

Thanks for Kedar_Pande, Greg_Deckler and bhanu_gautam replies. Are you currently addressing this issue? If not, you can refer to the following dax.

vyaningymsft_0-1729669395004.png

 

LY MTD Sales = 
VAR _currentDate = MAX('Table 2'[Inv Date])
VAR _previousYearDate = EDATE(_currentDate, -12)
VAR _item = SELECTEDVALUE('Table 2'[Item])
RETURN
CALCULATE(
    SUM('Table 2'[Amount]),
    FILTER(
        ALL('Table 2'),
        'Table 2'[Inv Date] <= _currentDate &&                  
        'Table 2'[Inv Date] >= _previousYearDate &&
        'Table 2'[Item] = _item
    )
)

 

Best Regards,
Yang

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 in the Power BI Forum

v-yaningy-msft
Community Support
Community Support

Hi, @rajasekar_o 

Thanks for Kedar_Pande Greg_Deckler and bhanu_gautam reply. They all give suggestions for modifying dax, you can try their methods and if they don't meet your needs, you can describe them in detail. Or just provide the pbix file without sensitive data for testing.

Best Regards,
Yang

Community Support Team

Kedar_Pande
Super User
Super User

@rajasekar_o ,

Corrected Measure:

LY MTD Sales =
VAR CurrentDate = MAX('date'[Date])
VAR PreviousYearStart = DATE(YEAR(CurrentDate)-1, MONTH(CurrentDate), 1)
VAR PreviousYearEnd = EOMONTH(PreviousYearStart, 0)
RETURN
CALCULATE(
[sales amount],
FILTER(
ALL('date'),
'date'[Date] >= PreviousYearStart &&
'date'[Date] <= PreviousYearEnd &&
'date'[Date] <= EDATE(CurrentDate, -12)
)
)

 

Greg_Deckler
Super User
Super User

@rajasekar_o Maybe:

LY MTD Sales =
  VAR CurrentDate = MAX('date'[Date])
  VAR PreviousYearDate = EDATE(CurrentDate, -12)
  VAR __Table = FILTER( ALL( 'Sales' ), 'Sales'[Date] <= PreviousYearDate && 'Sales'[Date] >= DATE( YEAR( CurrentDate) - 1, MONTH( CurrentDate ), 1 ) )
  VAR __Result = SUMX( __Table, [Amount] )
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
bhanu_gautam
Super User
Super User

@rajasekar_o , Try using below DAX

 

LY MTD Sales =
VAR CurrentDate = MAX('date'[Date])
VAR PreviousYearDate = EDATE(CurrentDate, -12)
RETURN
CALCULATE(
[sales amount],
FILTER(
ALL('date'),
'date'[Date] <= CurrentDate &&
'date'[Date] >= DATE(YEAR(CurrentDate)-1, MONTH(CurrentDate), 1) &&
'date'[Date] <= DATE(YEAR(CurrentDate)-1, MONTH(CurrentDate), DAY(CurrentDate))
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






NOT wroking

Inv DateItemQtyAmount
01-01-2023ITEM A5670
03-01-2023ITEM A6804
03-01-2023ITEM B4536
06-09-2023ITEM A3402
07-09-2023ITEM B7938
01-10-2023ITEM B4536
06-10-2023ITEM A81072
06-10-2023ITEM B4536
30-10-2023ITEM A81072
05-09-2024ITEM B3402
09-09-2024ITEM A7938
01-10-2024ITEM B5670
02-10-2024ITEM A81072
04-10-2024ITEM B3402

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors