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
StephenF
Responsive Resident
Responsive Resident

Power query M - how to define "this year" and "last year"

Hi,

 

I'm making a custom column and what it populated with 2020 and another with 2019.

 

How do I define this year and last year in this language?

1 ACCEPTED SOLUTION

I'm going to go with

 

if Date.Year(DateTime.LocalNow()) = ( [InvPayment_Due_Year] ) or Date.Year(DateTime.LocalNow()) = ( [InvPayment_Due_Year]+1 ) then 1 else 0

View solution in original post

7 REPLIES 7
bakerm00
Regular Visitor

since i've gone thru the pain of learning this today. 

determines if an end date is in this year or next (for a gantt visual filter)

= Table.AddColumn(#"convert progress to percent", "ganttyearfilter", each if([Forecast End Date] is null) then "0" else if(Date.IsInCurrentYear([Forecast End Date])) then "1" else if(Date.IsInNextYear([Forecast End Date]))then "2" else "99")

littlemojopuppy
Community Champion
Community Champion

Question: why define separate columns for this in Power Query when you can easily accomplish the same in DAX?

But if you have to, there are M functions to accomplish this...

Because I had this at the report level. I want it at the data source "edit query" level so I dont need to write a new formula for every report the data source references.

 

I've searched for half an hour on google and here and found nothing. The M documentation is not so good.

Are you trying to accomplish a year over year comparison?

No, Im creating a filter to limit data to this year and last year.

Oversimplifying, but you could simply have columns for year and amount and filter for Date.IsInPreviousYear or Date.IsInCurrentYear.  Having amounts in different fields could make measure writing later on more complicated than it needs to be

I'm going to go with

 

if Date.Year(DateTime.LocalNow()) = ( [InvPayment_Due_Year] ) or Date.Year(DateTime.LocalNow()) = ( [InvPayment_Due_Year]+1 ) then 1 else 0

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.