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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
dokat
Post Prodigy
Post Prodigy

Always return latest month last date value for the last 6 years

Hi Everyone,

 

I am trying to pull the Latest Month (YTD) value for the last 6 years. My table looks like below. I'd like to return corresponding value for 6/30/2017,6/30/2018,6/30/2019,6/30/2020,6/30/2021,6/30/2022.

 

next month will be 7/31/2017 and so on. 

 

Is there anyway to write a formula where it returns values for always the latest month ending date for the past 6 years.

 

Calendar Year
12/31/2017
12/31/2018
12/31/2019
12/31/2020
12/31/2021
4/1/2017
4/1/2018
4/1/2019
4/1/2020
4/1/2021
4/1/2022
4/30/2017
4/30/2018
4/30/2019
4/30/2020
4/30/2021
4/30/2022
6/30/2017
6/30/2018
6/30/2019
6/30/2020
6/30/2021
6/30/2022
6/1/2017
6/1/2018
6/1/2019
6/1/2020
6/1/2021
6/1/2022
3 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new table.

 

Untitled.png

 

monthenddate last six years = 
VAR _endofmonthtoday =
    EOMONTH ( TODAY (), 0 )
VAR _endofmonthnumber =
    MONTH ( _endofmonthtoday )
VAR _endofmonthdatenumber =
    DAY ( _endofmonthtoday )
VAR _currentyear =
    YEAR ( TODAY () )
VAR _sixyearsbefore = _currentyear - 5
RETURN
    FILTER (
        'Calendar',
        YEAR ( 'Calendar'[Date] ) >= _sixyearsbefore
            && YEAR ( 'Calendar'[Date] ) <= _currentyear
            && MONTH ( 'Calendar'[Date] ) = _endofmonthnumber
            && DAY ( 'Calendar'[Date] ) = _endofmonthdatenumber
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @dokat ;

You could create a new table :

New Date = 
var _maxdate=EOMONTH(MAX('Table'[Calendar Year]),0)
var _mindate=EOMONTH(MAX('Table'[Calendar Year]),-12*5)
return FILTER(CALENDAR(_mindate,_maxdate),FORMAT([Date],"mm-dd")=FORMAT(_maxdate,"mm-dd"))

The final show:

vyalanwumsft_0-1658977902521.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @dokat ;

You could create a new table :

New Date = 
var _maxdate=EOMONTH(MAX('Table'[Calendar Year]),0)
var _mindate=EOMONTH(MAX('Table'[Calendar Year]),-12*5)
return FILTER(CALENDAR(_mindate,_maxdate),FORMAT([Date],"mm-dd")=FORMAT(_maxdate,"mm-dd"))

The final show:

vyalanwumsft_0-1658977902521.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yalanwu-msft  Thank you it worked

Ashish_Mathur
Super User
Super User

Hi,

Your end objective is not clear.  Do you have sales figures there in another column or another other numeric column that you want to analyse.  Share some more information and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new table.

 

Untitled.png

 

monthenddate last six years = 
VAR _endofmonthtoday =
    EOMONTH ( TODAY (), 0 )
VAR _endofmonthnumber =
    MONTH ( _endofmonthtoday )
VAR _endofmonthdatenumber =
    DAY ( _endofmonthtoday )
VAR _currentyear =
    YEAR ( TODAY () )
VAR _sixyearsbefore = _currentyear - 5
RETURN
    FILTER (
        'Calendar',
        YEAR ( 'Calendar'[Date] ) >= _sixyearsbefore
            && YEAR ( 'Calendar'[Date] ) <= _currentyear
            && MONTH ( 'Calendar'[Date] ) = _endofmonthnumber
            && DAY ( 'Calendar'[Date] ) = _endofmonthdatenumber
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

@Jihwan_Kim 

Thank you it worked

Hi,

 

Thanks for sharing the formulas. My dates will be hard coded in date table.  is there way to bypass EOMONTH ( TODAY (), 0 ) function.  For ex: I could be pulling june numbers (6/30) in Sep, or Oct or Now...if i use the function it will always look for the current month and not the latest month in data table. 

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

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