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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
arnabmit
Helper I
Helper I

MTD when no month is selected on slicer

Hello good folks!

 

I have a simple query:
I have a MTD calculation based on a fact table, which works fine whenever a month is selected from the month slicer. However, the calculation always shows the MTD of Dec if no specific month is selected in the month slicer, and the slicer defaults to the [All] selection.

 

How do I force the MTD calculation to show the current month's data when no specific month is selected?

 

arnabmit_0-1669179291575.png

 

arnabmit_1-1669179366704.png

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but please try something like below whether it suits your requirement.

 

FM MTD fix: =
VAR _todaymonthstart =
    EOMONTH ( TODAY (), -1 ) + 1
VAR _todaymonthend =
    EOMONTH ( TODAY (), 0 )
RETURN
    IF (
        HASONEVALUE ( CalendarTable[Month] ) && HASONEVALUE ( CalendarTable[Year] ),
        TOTALMTD (
            DISTINCTCOUNTNOBLANK ( Fact_FM_Count[Count key] ),
            CalendarTable[Date]
        ),
        CALCULATE (
            DISTINCTCOUNTNOBLANK ( Fact_FM_Count[Count key] ),
            FILTER (
                ALL ( CalendarTable ),
                CalendarTable[Date] >= _todaymonthstart
                    && CalendarTable[Date] <= _todaymonthend
            )
        )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @arnabmit ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1669357173927.png

Table2: 

create with below dax formula

Table 2 =
ADDCOLUMNS (
    CALENDAR ( FIRSTDATE ( 'Table'[Date] ), LASTDATE ( 'Table'[Date] ) ),
    "Year", YEAR ( [Date] ),
    "Quarter", QUARTER ( [Date] ),
    "Month", MONTH ( [Date] )
)

vbinbinyumsft_1-1669357267905.png

2. create a measure with below dax formula

Measure =
VAR cur_year =
    SELECTEDVALUE ( 'Table 2'[Year] )
VAR cur_qtr =
    SELECTEDVALUE ( 'Table 2'[Quarter] )
VAR cur_month =
    SELECTEDVALUE ( 'Table 2'[Month] )
VAR today_date =
    TODAY ()
VAR _a =
    EOMONTH ( TODAY (), -1 ) + 1
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( cur_year ) )
            && NOT ( ISBLANK ( cur_qtr ) ) && NOT ( ISBLANK ( cur_month ) ), TOTALMTD ( DISTINCTCOUNTNOBLANK ( 'Table'[Sale] ), 'Table 2'[Date] ),
        ISBLANK ( cur_month ),
            CALCULATE (
                DISTINCTCOUNTNOBLANK ( 'Table'[Sale] ),
                FILTER (
                    ALL ( 'Table 2' ),
                    'Table 2'[Date] >= _a
                        && 'Table 2'[Date] <= today_date
                )
            )
    )

3. add three slicer with "Table 2" fields, add a card visual with measure

vbinbinyumsft_2-1669357454737.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but please try something like below whether it suits your requirement.

 

FM MTD fix: =
VAR _todaymonthstart =
    EOMONTH ( TODAY (), -1 ) + 1
VAR _todaymonthend =
    EOMONTH ( TODAY (), 0 )
RETURN
    IF (
        HASONEVALUE ( CalendarTable[Month] ) && HASONEVALUE ( CalendarTable[Year] ),
        TOTALMTD (
            DISTINCTCOUNTNOBLANK ( Fact_FM_Count[Count key] ),
            CalendarTable[Date]
        ),
        CALCULATE (
            DISTINCTCOUNTNOBLANK ( Fact_FM_Count[Count key] ),
            FILTER (
                ALL ( CalendarTable ),
                CalendarTable[Date] >= _todaymonthstart
                    && CalendarTable[Date] <= _todaymonthend
            )
        )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks! This worked!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.