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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Greyangel
Regular Visitor

M code to pull the next time a month shows up

I would like to build a query in which the results is the last day of june every year. Example since we are in march of 24 right now I would like the table to return 6/30/24, however on 7/1/25 I would like it to return 6/30/26.

1 ACCEPTED SOLUTION
rubinboer
Resolver II
Resolver II

hi @Greyangel 

 

welcome tot he community.

 

you could do the follwing to determine it:

 

 

let
    EndOfJuneDate = (yourEvaluationDate as date) =>
        let
            currentYear = Date.Year(yourEvaluationDate),
            nextYear = currentYear + 1,
            lastDayOfJune = #date(currentYear, 6, 30),
            nextYearFirstDay = #date(nextYear, 1, 1)
        in
            if yourEvaluationDate >= lastDayOfJune then
                nextYearFirstDay
            else
                lastDayOfJune 
in
    EndOfJuneDate

 

 

This is what happens

  • The if statement checks whether yourEvaluationDate (you can have it check today() as well) is greater than or equal to lastDayOfJune.
  • If true (meaning the input date is on or after June 30th), it returns nextYearFirstDay.
  • Otherwise (if the input date is before June 30th), it returns lastDayOfJune.

View solution in original post

1 REPLY 1
rubinboer
Resolver II
Resolver II

hi @Greyangel 

 

welcome tot he community.

 

you could do the follwing to determine it:

 

 

let
    EndOfJuneDate = (yourEvaluationDate as date) =>
        let
            currentYear = Date.Year(yourEvaluationDate),
            nextYear = currentYear + 1,
            lastDayOfJune = #date(currentYear, 6, 30),
            nextYearFirstDay = #date(nextYear, 1, 1)
        in
            if yourEvaluationDate >= lastDayOfJune then
                nextYearFirstDay
            else
                lastDayOfJune 
in
    EndOfJuneDate

 

 

This is what happens

  • The if statement checks whether yourEvaluationDate (you can have it check today() as well) is greater than or equal to lastDayOfJune.
  • If true (meaning the input date is on or after June 30th), it returns nextYearFirstDay.
  • Otherwise (if the input date is before June 30th), it returns lastDayOfJune.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.