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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.