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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
newgirl
Helper V
Helper V

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
Helper V
Helper V

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
Helper V
Helper V

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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