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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

M Query for Previous Year Till Date

Hello,

I have a requirement to show the PYTD in data which i need to achieve by adding into M query. 

I tried the below approach and its giving the previous year but only for two months:

 

#"FILTER"=Table.SelectRows(#"Changed Type",each ([Transaction Detail.Production Period] >=#date(Date.Year(DateTime.LocalNow()) -1 , Date.Month(DateTime.LocalNow())-1, 1))
and ([Transaction Detail.Production Period] <#date(Date.Year(DateTime.LocalNow()) -1 , Date.Month(DateTime.LocalNow())+1, 1)))
in
#"FILTER"

 

I need to show it for all months from Jan 2021 to Dec 2021.

Kindly help.

Thanks 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , As you need full year, You can compare to year -1

 

#"FILTER"=Table.SelectRows(#"Changed Type",each (Date.Year([Transaction Detail.Production Period]) =Date.Year(DateTime.LocalNow()) -1 ))
in
#"FILTER"

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,
How can i get all three in one like : 
MTD, YTD, PYMTD and PYYTD

HotChilli
Super User
Super User

You could hardcode the months. 1 and 12

Is it really previous year To date or is it subtract 1 year and return the calendar year's data?

amitchandak
Super User
Super User

@Anonymous , As you need full year, You can compare to year -1

 

#"FILTER"=Table.SelectRows(#"Changed Type",each (Date.Year([Transaction Detail.Production Period]) =Date.Year(DateTime.LocalNow()) -1 ))
in
#"FILTER"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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