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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.