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
WannaBe
Frequent Visitor

Dynamic data filtering based on selected date

Hello,

I have 2 tables linked by a date field.
#1 - Calendar = fields(Date)

#2 - UserActivity = fields (StartDate, Email)

Calendar table go from 2021-01-01 until 2024-07-31.
I need with a date slicer choose the period that I want and from there I need to apply the following logic.

-> Given at filtered dates A to B, find user’s (Email) most recent use and go back 12 months to count all uses per user.
-> If count is equal or higher than 3, flag these user with a true flag.
-> having a count of all users that have the flag identify as true.
Hope someone can help on that one.

Tank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @WannaBe ,

I create two tables as you mentioned.

Calendar = CALENDAR(DATE(2021,1,1),DATE(2024,7,31))

vyilongmsft_0-1724812436138.png

vyilongmsft_1-1724812485634.png

Then I create two measures and here is the DAX code.

LastUseDate =
CALCULATE (
    MAX ( 'Table'[StartDate] ),
    FILTER (
        'Table',
        'Table'[StartDate] >= MIN ( 'Calendar'[Date] )
            && 'Table'[StartDate] <= MAX ( 'Calendar'[Date] )
    )
)

vyilongmsft_2-1724812940394.png

UseLast12 = 
CALCULATE(
    COUNT('Table'[Email]),
    FILTER(
        'Table',
        'Table'[StartDate] <= [LastUseDate] &&
        'Table'[StartDate] > EDATE([LastUseDate], -12)
    )
)

vyilongmsft_3-1724812995372.png

Finally I get this measure and get what you want.

CountUser = 
VAR _User = IF('Table'[UseLast12] >= 3,"T","F")
RETURN
CALCULATE(
    COUNTROWS(
        FILTER(
            'Table',
            _User = "F"
        )
    )
)

vyilongmsft_4-1724813122786.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
WannaBe
Frequent Visitor

Thank you very much @Anonymous .
This helps a lot, but I'm still having trouble getting exactly what I'm looking for.
The highlighted row for example shows 1 as "UseLast12" and when I click on that row we see 4 as "CountUser".
This seems true.
In the date range used, it has accessed 1 time and 4 in total in the last 12 months.
However I would like to not have to click on each of the rows in order to have the total for the last 12 months. I would like to have the grand total of everyone for their usage in the last 12 months.
So in the example have 4 for the last 12 months and not 1.
Do you have any idea how I can get this number?

2024-08-28_14-55-59.jpg

Anonymous
Not applicable

Hi @WannaBe ,

I create two tables as you mentioned.

Calendar = CALENDAR(DATE(2021,1,1),DATE(2024,7,31))

vyilongmsft_0-1724812436138.png

vyilongmsft_1-1724812485634.png

Then I create two measures and here is the DAX code.

LastUseDate =
CALCULATE (
    MAX ( 'Table'[StartDate] ),
    FILTER (
        'Table',
        'Table'[StartDate] >= MIN ( 'Calendar'[Date] )
            && 'Table'[StartDate] <= MAX ( 'Calendar'[Date] )
    )
)

vyilongmsft_2-1724812940394.png

UseLast12 = 
CALCULATE(
    COUNT('Table'[Email]),
    FILTER(
        'Table',
        'Table'[StartDate] <= [LastUseDate] &&
        'Table'[StartDate] > EDATE([LastUseDate], -12)
    )
)

vyilongmsft_3-1724812995372.png

Finally I get this measure and get what you want.

CountUser = 
VAR _User = IF('Table'[UseLast12] >= 3,"T","F")
RETURN
CALCULATE(
    COUNTROWS(
        FILTER(
            'Table',
            _User = "F"
        )
    )
)

vyilongmsft_4-1724813122786.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.