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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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