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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

Reply
y5famfnatudu
Resolver I
Resolver I

number of days x month ago, with slicer for working days

Hello, I wish you all a wonderful year.

I have this measure which calculates the number of days in the whole previous month

Days m01 = 
VAR __MonthsBack = 1
VAR __Day =
    CALCULATE (
        COUNTROWS ( 'Date 2' ),
        DATESINPERIOD (
            'Date 2'[Date],
            EOMONTH ( TODAY (), - __MonthsBack ),
            -1,
            MONTH
        )
    )
RETURN
    __Day

I have a slicer from the Date Table which is coming from the column Date[IsWorkingDay]
Unfortunately, whatever value I select from the slicer (0, 1), the value of the measure is showing 31 (number of days in DEC, which is last month)
How can I make this measure be dynamic to filter based on the slicer?

Best regards,
Simon

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try

Days m01 =
VAR __MonthsBack = 1
VAR __Day =
    CALCULATE (
        COUNTROWS ( 'Date 2' ),
        KEEPFILTERS (
            DATESINPERIOD (
                'Date 2'[Date],
                EOMONTH ( TODAY (), - __MonthsBack ),
                -1,
                MONTH
            )
        )
    )
RETURN
    __Day

View solution in original post

6 REPLIES 6
johnt75
Super User
Super User

Try

Days m01 =
VAR __MonthsBack = 1
VAR __Day =
    CALCULATE (
        COUNTROWS ( 'Date 2' ),
        KEEPFILTERS (
            DATESINPERIOD (
                'Date 2'[Date],
                EOMONTH ( TODAY (), - __MonthsBack ),
                -1,
                MONTH
            )
        )
    )
RETURN
    __Day

Perfect, thank you @johnt75 so much, but what was the point of adding Keepfilters, I didn't quite get it?

If 'Date 2' is marked as a date table, or also I think if the date column is used in a one-to-many relationship, when you apply a filter to the date column then all other filters on the table are removed automatically, to simplify time intelligence type calculations. If you want to manipulate the dates but retain other filters on e.g. working days or days of the week then you need to use KEEPFILTERS.

rohit1991
Super User
Super User

To make your measure dynamic based on the slicer for Date[IsWorkingDay], update it as follows:

 

Days m01 =
VAR __MonthsBack = 1
VAR __StartDate = EOMONTH(TODAY(), -__MonthsBack) + 1
VAR __EndDate = EOMONTH(TODAY(), -__MonthsBack)
RETURN
    CALCULATE(
        COUNTROWS('Date 2'),
        'Date 2'[Date] >= __StartDate && 'Date 2'[Date] <= __EndDate
    )

 

This ensures the slicer filters are respected, dynamically adjusting the count of days based on IsWorkingDay.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

And even when I fix the date range, it shows 31 (number of days in in December, which is the previous month) all the time, no matter which value in the slicer is selected

Thank you, but this shows blank, no values are showing no matter which slicer value I select

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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