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
MSuser5
Helper III
Helper III

Based on date slicer- display current month and previous month names

Hi All,

 

I have calender[date] column which is being used in slicer hierarchy level based on selection it should display current month& year, previous month& year  in card label.

 

example screenshot :

if user selected in slicer  Jan'2023 then

current month_year = Jan 2023

pre month_Year = Dec 2022

 

Screenshot 2023-03-22 230622kk.png

 

Thanks in advance.

 

1 ACCEPTED SOLUTION
MohammadLoran25
Solution Sage
Solution Sage

Hi @MSuser5 ,

Follow these steps:

 

1-Create a calculated column as:

YearMonth = CONVERT(FORMAT(DateTable[Date],"YYYYMM"),INTEGER)
 
2-Create another calculated column as:
YearMonthOrder = RANKX (
    DateTable,
    DateTable[YearMonth],
    ,
    ASC,
    DENSE
)
 
3-CurrentMonth Measure is as below:
CurrentMonth =
CALCULATE (
    MIN ( DateTable[MonthName] ),
    FILTER (
        ALL ( DateTable ),
        DateTable[YearMonthOrder] = MAX ( DateTable[YearMonthOrder] )
    )
)
 
4-PrevMonth Measure is:
PrevMonth =
CALCULATE (
    MIN ( DateTable[MonthName] ),
    FILTER (
        ALL ( DateTable ),
        DateTable[YearMonthOrder]
            MAX ( DateTable[YearMonthOrder] ) - 1
    )
)
 
If this answer solves your problem, please mark it as an accepted solution so the others would find what they need easier.
Regards,
Loran

View solution in original post

2 REPLIES 2
MohammadLoran25
Solution Sage
Solution Sage

Hi @MSuser5 ,

Follow these steps:

 

1-Create a calculated column as:

YearMonth = CONVERT(FORMAT(DateTable[Date],"YYYYMM"),INTEGER)
 
2-Create another calculated column as:
YearMonthOrder = RANKX (
    DateTable,
    DateTable[YearMonth],
    ,
    ASC,
    DENSE
)
 
3-CurrentMonth Measure is as below:
CurrentMonth =
CALCULATE (
    MIN ( DateTable[MonthName] ),
    FILTER (
        ALL ( DateTable ),
        DateTable[YearMonthOrder] = MAX ( DateTable[YearMonthOrder] )
    )
)
 
4-PrevMonth Measure is:
PrevMonth =
CALCULATE (
    MIN ( DateTable[MonthName] ),
    FILTER (
        ALL ( DateTable ),
        DateTable[YearMonthOrder]
            MAX ( DateTable[YearMonthOrder] ) - 1
    )
)
 
If this answer solves your problem, please mark it as an accepted solution so the others would find what they need easier.
Regards,
Loran

@MohammadLoran25 ,

 

Thank you so much it's working as expected.

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.