Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
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 |
Solved! Go to Solution.
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.
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
)
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:
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.
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:
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.
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.
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.
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
)
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 48 | |
| 40 | |
| 37 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 70 | |
| 67 | |
| 32 | |
| 27 | |
| 25 |