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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Tanushree_Kapse
Impactful Individual
Impactful Individual

Calculate the number of months.

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.

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Tanushree_Kapse , Try like

 

No. of months= MONTH(Maxx(allselected(Table), Table[Date]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

selimovd
Super User
Super User

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

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

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])

 
selimovd
Super User
Super User

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

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
amitchandak
Super User
Super User

@Tanushree_Kapse , Try like

 

No. of months= MONTH(Maxx(allselected(Table), Table[Date]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thankyou @amitchandak , that helped!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.