cancel
Showing results for
Did you mean:

## Lable YTD Rows in Calendar

I'm trying to create a way to label all YTD comparable rows in a calendar table.  I got close but it doesn't handle leap years (see screenshot)

Can anyone assist in a proper formula that would return true for all YTD dates of prior years?  For example, today I should see True on all rows for January 1-June 6th of all years.

Current attempt is an attempt to convert the row's day to the same day this year and then check if that's in current YTD:

= Table.AddColumn(#"Calculated Quarter", "YOY YTD", each Date.IsInYearToDate( #date(Date.Year(DateTime.Date(DateTime.LocalNow())),Date.Month([Date]), Date.Day([Date]))) )

1 ACCEPTED SOLUTION

Accepted Solutions

ShawnKeeneTF

The formula will return true for each of those dates.

Regards

The following M code generates all dates from 1st Jan 2020 to 31st Dec 2023 and uses the formula to mark each date as in YTD or not so you can check if it does what you want. The screenshot in your question was not readable so maybe there's some other subtlety in the question that it would reveal.

`letSource = List.Dates(#date(2020,1,1), Duration.TotalDays(#date(2023,12,31) - #date(2020,1,1)) + 1 , #duration(1,0,0,0)),#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),#"Add in Year" = Table.AddColumn(   #"Renamed Columns",    "Error Free Version",    each Date.IsInYearToDate(    Date.AddYears( [Date], Date.Year(DateTime.LocalNow()) - Date.Year([Date]) )   ),   type logical   )in#"Add in Year"`

4 REPLIES 4

Good day ShawnKeeneTF,

An idea would be to use AddYears to add years to “Date”. AddYears takes care of leap years sensibly.

1. The number of years to add is year(this year)-year(date).
2. Then check if that date is in the current year to date.

Here is M code, with the formula which gives the error and then the formula using AddYears.

Hope this helps.

`let   Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtc30zcyUIrViVYystQ3grENDUDixkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),   #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),   #"Added Error Version" = Table.AddColumn(      #"Changed Type",       "Errored Version",       each Date.IsInYearToDate(          #date(Date.Year(DateTime.Date(DateTime.LocalNow())),Date.Month([Date]), Date.Day([Date]))      ),       type logical   ),   #"Added Error-free Version" = Table.AddColumn(      #"Added Error Version",       "Error Free Version",       each Date.IsInYearToDate(          Date.AddYears( [Date], Date.Year(DateTime.LocalNow()) - Date.Year([Date]) )      ),      type logical)in   #"Added Error-free Version"`

which gives the result

I found something like this online but I don't think this is exactly what I'm after. I'll give it a try though.

The problem is that I want for example June 1st to show up as true for all years. Basically all dates that are within the completed days this year.

So all these should be true for example

June 1 2020

June 1 2021

June 1 2022

June 1 2023

ShawnKeeneTF

The formula will return true for each of those dates.

Regards

The following M code generates all dates from 1st Jan 2020 to 31st Dec 2023 and uses the formula to mark each date as in YTD or not so you can check if it does what you want. The screenshot in your question was not readable so maybe there's some other subtlety in the question that it would reveal.

`letSource = List.Dates(#date(2020,1,1), Duration.TotalDays(#date(2023,12,31) - #date(2020,1,1)) + 1 , #duration(1,0,0,0)),#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),#"Add in Year" = Table.AddColumn(   #"Renamed Columns",    "Error Free Version",    each Date.IsInYearToDate(    Date.AddYears( [Date], Date.Year(DateTime.LocalNow()) - Date.Year([Date]) )   ),   type logical   )in#"Add in Year"`

Thanks, I see the offset you're using that makes this work when the earlier examples I had seen online didn't account for all years.  Thank you so much for this.

Announcements

#### Tuesday Tip | How to Get Community Support

It's time for another Tuesday Tip, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.       This Week: All About Community Support Whether you're a seasoned community veteran or just getting started, you may need a bit of help from time to time! If you need to share feedback with the Community Engagement team about the community or are looking for ways we can assist you with user groups, events, or something else, Community Support is the place to start.   Community Support is part of every one of our communities, accessible to all our community members.   Within each community's Community Support page, you'll find three distinct areas, each with a different focus to help you when you need support from us most. Power Apps: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pa_community_support Power Automate: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpa_community_support Power Pages: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpp_community_support Copilot Studio: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pva_community-support   Community Support Form If you need more assistance, you can reach out to the Community Team via the Community support form. Choose the type of support you require and fill in the form accordingly. We will respond to you promptly.    Thank you for being an active part of our community. Your contributions make a difference!   Best Regards, The Community Management Team

#### Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp