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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
newgirl
Post Patron
Post Patron

Default Slicer Selection with YearMonth

Hello, everyone! Hope somebody could help me out. 

I need a Monthyear slicer for a page but I wanted it to be dynamic in a way that the reader doesn't have to filter the slicer every time it's a new month - so this is like creating a default TODAY slicer date.

Currently, I have this calculated column in my Calendar table:

As of Month = 
VAR _today = TODAY()
RETURN
IF (
    (
        ( YEAR ( _today ) * 100 )
            + MONTH ( _today )
    )
        = (
            ( YEAR ( 'Calendar'[Date] ) * 100 )
                + MONTH ( 'Calendar'[Date] )
        ),
    "Filtered Month",
    CONVERT (
        ( YEAR ( 'Calendar'[Date] ) * 100 )
            + MONTH ( 'Calendar'[Date] ),
        STRING
    )
)

and what it basically does is if the Date column falls within the current YearMonth, then show as " Filtered Month". Else, show the YearMonth as is.

Now, this is how my Calculated Column  looks in the slicer:

yearmonth slicer.JPG 

 

My problem now is: I need to modify my DAX in a way that:

If the current date is Day 1 of the month, then it should treat the current date as previous day (Ex. If today is June 1, then it should treat today as if it's May 31 so that the calendar dates with 202205 will be classified as "Filtered Month". However, if it's not Day 1, say June 2, then it should treat today as current date and so the calendar dates with 202206 will be classified as "Filtered Month".)

1 ACCEPTED SOLUTION
newgirl
Post Patron
Post Patron

I was able to modify it this way:

As of Month = 
VAR _actualtoday = TODAY()
VAR _today = if(DAY(_actualtoday)=1,EOMONTH(_actualtoday,-1),_actualtoday)
RETURN
IF (
    (
        ( YEAR ( _today ) * 100 )
            + MONTH ( _today )
    )
        = (
            ( YEAR ( 'Calendar'[Date] ) * 100 )
                + MONTH ( 'Calendar'[Date] )
        ),
    "Filtered Month",
    CONVERT (
        ( YEAR ( 'Calendar'[Date] ) * 100 )
            + MONTH ( 'Calendar'[Date] ),
        STRING
    )
)

View solution in original post

1 REPLY 1
newgirl
Post Patron
Post Patron

I was able to modify it this way:

As of Month = 
VAR _actualtoday = TODAY()
VAR _today = if(DAY(_actualtoday)=1,EOMONTH(_actualtoday,-1),_actualtoday)
RETURN
IF (
    (
        ( YEAR ( _today ) * 100 )
            + MONTH ( _today )
    )
        = (
            ( YEAR ( 'Calendar'[Date] ) * 100 )
                + MONTH ( 'Calendar'[Date] )
        ),
    "Filtered Month",
    CONVERT (
        ( YEAR ( 'Calendar'[Date] ) * 100 )
            + MONTH ( 'Calendar'[Date] ),
        STRING
    )
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.