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

#### A Celebration of What We've Achieved--And Announcing Our Winners

As the sun sets on the #SummerofSolutions Challenge, it's time to reflect and celebrate! The journey we embarked upon together was not just about providing answers – it was about fostering a sense of community, encouraging collaboration, and unlocking the true potential of the Power Platform tools.   From the initial announcement to the final week's push, the Summer of Solutions Challenge has been a whirlwind of engagement and growth. It was a call to action for every member of our Power Platform community, urging them to contribute their expertise, engage in discussions, and elevate collective knowledge across the community as part of the low-code revolution.   Reflecting on the Impact As the challenge ends, it's essential to reflect on the impact it’s had across our Power Platform communities: Community Resilience: The challenge demonstrated the resilience of our community. Despite geographical distances and diverse backgrounds, we came together to contribute, learn, and collaborate. This resilience is the cornerstone of our collective strength.Diverse Expertise: The solutions shared during the challenge underscore the incredible expertise within our community. From intricate technical insights to creative problem-solving, our members showcased their diverse skill sets, enhancing our community's depth.Shared Learning: Solutions spurred shared learning. They provided opportunities for members to grasp new concepts, expand their horizons, and uncover the Power Platform tools' untapped potential. This learning ripple effect will continue to shape our growth. Empowerment: Solutions empowered community members. They validated their knowledge, boosted their confidence, and highlighted their contributions. Each solution shared was a step towards personal and communal empowerment. We are proud and thankful as we conclude the Summer of Solutions Challenge. The challenge showed the potential of teamwork, the benefit of knowledge-sharing, and the resilience of our Power Platform community. The solutions offered by each member are more than just answers; they are the expression of our shared commitment to innovation, growth, and progress!   Drum roll, Please... And now, without further ado, it's time to announce the winners who have risen above the rest in the Summer of Solutions Challenge!   These are the top community users and Super Users who have not only earned recognition but have become beacons of inspiration for us all.   Power Apps Community:  Community User Winner: @SpongYe Super User Winner: Pending Acceptance Power Automate Community:  Community User Winner: @trice602 Super User Winner: @Expiscornovus  Power Virtual Agents Community: Community User Winner: Pending AcceptanceSuper User: Pending Acceptance Power Pages Community: Community User Winner: @OOlashyn Super User Winner: @ChristianAbata   We are also pleased to announced two additional tickets that we are awarding to the Overall Top Solution providers in the following communities:    Power Apps: @LaurensM   Power Automate: @ManishSolanki    Thank you for making this challenge a resounding success. Your participation has reaffirmed the strength of our community and the boundless potential that lies within each of us. Let's keep the spirit of collaboration alive as we continue on this incredible journey in Power Platform together.Winners, we will see you in Vegas! Every other amazing solutions superstar, we will see you in the Community!Congratulations, everyone!