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
JeroenHD
Helper I
Helper I

date.Isinpreviousn Year strange result

Hello Team, 

I have a question, because this appears kind of strange to me. Probably there's a good explanation for this, but i don't see it. 

 

I have added a column with IsInPreviousNYears([Customer_Modified_On],8 ) which is a date-type column. 
However on a date of 23-2-2021 it returns FALSE. I would expect TRUE as it was in the Previous 8 Years.

Does anybody have an idea what goes wrong here?

 

Screenshot 2021-03-01 111044.png

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

Hi, @JeroenHD 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may add a new step with the following m codes.

= Table.AddColumn(#"Changed Type", "Custom", each let 
end = Date.From(DateTime.LocalNow()),
start = Date.AddYears(end,-8)
in 
[Date]>=start and [Date]<=end)

 

Result(Today is 3/4/2021):

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @JeroenHD 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may add a new step with the following m codes.

= Table.AddColumn(#"Changed Type", "Custom", each let 
end = Date.From(DateTime.LocalNow()),
start = Date.AddYears(end,-8)
in 
[Date]>=start and [Date]<=end)

 

Result(Today is 3/4/2021):

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Payeras_BI
Super User
Super User

Hi @JeroenHD ,

"Note that this function will return false when passed a value that occurs within the current year."

 

https://docs.microsoft.com/en-us/powerquery-m/date-isinpreviousnyears

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain
JeroenHD
Helper I
Helper I

i solved it in Dax now, but i am still curious if anyone can help me figure out what the deal is in Power Query.

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.

Top Solution Authors