Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi,
Let me make my question simple.
I have a slicer where one can choose a date. And I have a date table with, amongst others, a month-end-flag (Y for the last date of the month) and a month-key.
The month-key for all rows in the same month is equal.
Now, if I choose for instance 5-1-2023, I want LastDate to return 31-1-2023, the last day of January.
_monthkey returns the right value, but then the CALCULATE returns nothing.
What am I doing wrong??
Regards
Ron
Solved! Go to Solution.
@PowerRon Oh, sorry, the first one should have been:
LastDate =
var _monthkey = SELECTEDVALUE('Calendar'[Date])
var _result = EOMONTH(_monthkey, 0)
RETURN
_result
Also, the MAXX is just there to grab the value out of the table. You could also have used MINX. You might be able to use SELECTCOLUMNS instead of MINX or MAXX.
Hi @Greg_Deckler
one more question.
You showed me how to quickly get the last day of the month when I grab a date from a slicer.
Is there also a way to, based on grabbed date from a slicer, easily get the first date of the month?
@PowerRon Sure:
FirstDate =
VAR _Date = SELECTEDVALUE('Calendar'[Date])
VAR _Result = DATE(YEAR(_Date), MONTH(_Date), 1)
RETURN
_Result
@PowerRon 2 Ways of doing this:
LastDate =
var _monthkey = SELECTEDVALUE('Calendar'[MO_KEY])
var _result = EOMONTH(_monthkey, 0)
RETURN
_result
LastDate =
var _monthkey = SELECTEDVALUE('Calendar'[Date])
var _table = FILTER(ALL('Calendar'), MONTH([Date]) = MONTH(_monthkey) && YEAR([Date]) = YEAR(_monthkey) && [End of Month Flag] = "Y")
var _result = MAXX(_table, [Date])
RETURN
_result
Hi @Greg_Deckler
When I select 3-1-2022, your first solution gives me 31-5-1901, and the second one 31-1-2022.
So the second one works. Thnx.
Because in every month there is just one row with End-of-Month-Flag = Y, do we then still need the iterating MAXX?
@PowerRon Oh, sorry, the first one should have been:
LastDate =
var _monthkey = SELECTEDVALUE('Calendar'[Date])
var _result = EOMONTH(_monthkey, 0)
RETURN
_result
Also, the MAXX is just there to grab the value out of the table. You could also have used MINX. You might be able to use SELECTCOLUMNS instead of MINX or MAXX.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
87 | |
87 | |
84 | |
66 | |
49 |
User | Count |
---|---|
130 | |
110 | |
93 | |
70 | |
67 |