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
Anonymous
Not applicable

DatesYTD Calculate YTD across multiple years

I'm trying to calculate YTD values across multiple years and thought I had it until I realized the DATESYTD appears to sum backwards from 12/31 to the date added to the context.  For example

 

YTDAttyHours = CALCULATE(SUM('Timekeeper Details (Last 5 years)'[Atty Hours]),DATESYTD((Dates[Date]),"11/30"))
 
the "11/30" actually gives me the sum of each date AFTER 11/30 instead of YTD through 11/30. Can someone help me figure out how to do YTD calculations intead of this backwards calculation?
 
Thanks!
6 REPLIES 6
KNP
Super User
Super User

Hi @Anonymous , 

 

Please ignore if you need a DAX solution.

In M you could do it like this (or any variation of this).

 

let
    //***Source data***
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdnLrRtZEARRX95aAJlR/bVFGP/dGBGiCPBmbGN1D6oWja7fv3/yeObBM9fPr588f/779fuHTtNp67R3Ojqdna5Od6c8pcn7I4CIIEKIGCKIiCLCiDgQBzYHcSAOxIE4EAfiQByIY8QxNo/Hk16xNU2nrdPe6eh0dro63Z1eK1ZN3h8BRAQRQsQQQUQUEUbEgTiwOYgDcSAOxIE4EAfmeDyn12RN02nrtHc6Op2drk53p9eaVJP3RwARQYQQMUQQEUWEEXEgDmwO4kAciANxIA7EgTgQx4hjbB6P59YrtqbptHXaOx2dzk5Xp7vTa8WqyfsjgIggQogYIoiIIsKIOBAHNgdxIA7EgTgQB+JAHIhjbB6P597rtKbptHXaOx2dzk5Xp7vTa52qyfsjgIggQogYIoiIIsKIOBAHNgdxIA7EgTgQB+JAHIhjxDE2j8fz6BVb03TaOu2djk5np6vT3em1YtXk/RFARBAhRAwRREQRYUQciAObgzgQB+JAHIgDcSAOxDE2j8fz7HVa03TaOu2djk5np6vT3em1TtXk/RFARBAhRAwRREQRYUQciAObgzgQB+JAHIgDcSAOxDHiGJvH43n1iq1pOm2d9k5Hp7PT1enu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ogIIoSIIYKIKCKMiANxYHMQB+JAHIgDcSAOxIE4Rhxj83jfdr5XrP+yV9o67Z2OTmenq9Pd6XMXXFZM/rJ3E0GEEDFEEBFFhBFxIA5sDuJAHIgDcSAOxIE4EMfYPN53nO916j/qlbZOe6ej09np6nR3+twFl3WSP+rdRBAhRAwRREQRYUQciAObgzgQB+JAHIgDcSAOxDHiGJvH3zsOz69vrDVNp63T3unodHa6Ot2d/t0Fv5q8PwKICCKEiCGCiCgijIgDcWBzEAfiQByIA3EgDsSBOEYcY/P4ewNaVmxN02nrtHc6Op2drk53p393wXXFqgkgIogQIoYIIqKIMCIOVsd//wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Value", Int64.Type}}),

    //***Added Year for grouping purposes***
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),

    //***Added Day of Year for filtering***
    #"Added Custom" = Table.AddColumn(#"Inserted Year", "Custom", each Date.DayOfYear([Date])),

    //***Sorted to find MAX Day of Year for current year***
    #"Sorted Rows" = Table.Sort(#"Added Custom",{{"Date", Order.Descending}}),

    //***Drill down to define DayInYear used in filtering***
    DayInYear = #"Sorted Rows"{0}[Custom],

    //***Filter rows to show less than or equal to 'DayInYear'***
    #"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each [Custom] <= DayInYear),

    //***Group by Year***
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Year"}, {{"SumValue", each List.Sum([Value]), type number}})
in
    #"Grouped Rows"

 

Hope this helps.

 

Regards,

Kim

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
parry2k
Super User
Super User

@Anonymous not sure wht you mean each date after, giving 11/30 , you are telling what your year looks like and in this case it would be Dec 1st to Nov 30th.

 

So for each year, the ytd range will Dec 1st and Nov 30th and will give you the number. What is the actual issue? can you share sample data dn explain what is not working and what you are expecting?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

I would just like a simple YTD calculation.  i.e. Jan 1st through the current date.  When I put in "11/30" it gives me 11/30 through the end of the year.  This is the opposite of YTD.

@Anonymous you don't need to put 11/30 value, no value for 2nd parameter.

 

Would appreciate Kudos 🙂 if my solution helped.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2kBut I'm trying to calculate YTD across Years with Years as Axis labels.  If I don't put it a date, it won't know what month to stop at for previous years, correct?

@Anonymous it would, you have to try it to test it. and read about DATESYTD function here   Would appreciate Kudos 🙂 if my solution helped.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.