Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi All,
I have a Date Slicer, wherein I want to have the "Latest Date" selected always.
For this I created a column
SlicerDate= IF(Table[Date]= MAX(Table[Date]),"Latest Date")
And this works fine when I pull this in the slicer and keep it single selected so that the Latest Date is selected always by default.
Now,
I want to calculate the No. of Months till the selected date:
If in the slicer, the latest date is 31-07-2021, then the No. of months should be 7.
I created this measure:
No. of months= MONTH(SELECTEDVALUE(Table[SlicerDate]))
But this is giving error, as I have the "Latest Date" text in this column.
So, how do I calculate the No of months...with the date selected in this slicer?
@amitchandak @Fowmy @Anonymous @daxer-almighty
Please help!
Thanks.
Solved! Go to Solution.
Hey @Tanushree_Kapse ,
if you want to return that as a measure, the following code should do it.
No of month measure =
VAR vLatestDate =
CALCULATE(
MAX( Table[Date] ),
ALL( Table[Date] )
)
VAR vCurrentDate =
MAX( Table[Date] )
VAR vDiff =
DATEDIFF(
vCurrentDate,
vLatestDate,
MONTH
)
RETURN
vDiff
If you want that as a calculated column, this should do it:
No of month column =
VAR vLatestDate = MAX(Table[Date])
VAR vCurrentDate = Table[Date]
VAR vDiff =
DATEDIFF(
vCurrentDate,
vLatestDate,
MONTH
)
RETURN
vDiff
I am not sure if I understand your problem statement correctly, but the error you are getting because the [SlicerDate] Column is actually not the Date type column but a text column.
Try doing this:
SlicerDate= IF(Table[Date]= MAX(Table[Date]),Table[Date])
Hey @Tanushree_Kapse ,
if you want to return that as a measure, the following code should do it.
No of month measure =
VAR vLatestDate =
CALCULATE(
MAX( Table[Date] ),
ALL( Table[Date] )
)
VAR vCurrentDate =
MAX( Table[Date] )
VAR vDiff =
DATEDIFF(
vCurrentDate,
vLatestDate,
MONTH
)
RETURN
vDiff
If you want that as a calculated column, this should do it:
No of month column =
VAR vLatestDate = MAX(Table[Date])
VAR vCurrentDate = Table[Date]
VAR vDiff =
DATEDIFF(
vCurrentDate,
vLatestDate,
MONTH
)
RETURN
vDiff
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
28 | |
12 | |
10 | |
10 | |
6 |