Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
1 year ago
Solved

Create a dynamic filter that is calculated from the selected date

Good

I have a table with the following columns: Patient, Date, Accepted.

PatientDate Accepted
101/01/2020T
102/01/2020T
103/01/2020F
104/01/2020

F

201/01/2020F
201/01/2021T
201/01/2022T
202/01/2022T

I have a date filter included in the report.

I want to create a dynamic filter that calculates if a patient is active, I consider a patient to be active if by the filtered date they have at least one accepted measurement. For example, if I have filtered the date range 01/01/2020 - 31/01/2020 it should appear that patient 1 is active but patient 2 is not, but if I filter 03/01/2020 - 31/01/2021 patient 2 would be the only active one.

How could I do that?

  • Hi Syndicate_Admin 
    To achieve a wanted "segmentation" you can apply these steps:
    1. You can  use a disconnected date table :

    2. Create Dax measure :

    Active check =
    var min_d = min('calendar'[Date])
    var max_d = max('calendar'[Date])
    var count_active =
    CALCULATE(DISTINCTCOUNT('Table'[Patient]), 'Table'[Date]>=min_d && 'Table'[Date]<=max_d && 'Table'[Accepted]= "T")
    RETURN
    if (ISBLANK(count_active),"Not active", "Active")

    3. use a date table as a filter / slicer

    The pbix is attached

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

2 Replies

  • Hi Syndicate_Admin 
    To achieve a wanted "segmentation" you can apply these steps:
    1. You can  use a disconnected date table :

    2. Create Dax measure :

    Active check =
    var min_d = min('calendar'[Date])
    var max_d = max('calendar'[Date])
    var count_active =
    CALCULATE(DISTINCTCOUNT('Table'[Patient]), 'Table'[Date]>=min_d && 'Table'[Date]<=max_d && 'Table'[Accepted]= "T")
    RETURN
    if (ISBLANK(count_active),"Not active", "Active")

    3. use a date table as a filter / slicer

    The pbix is attached

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

  • Power BI Implementation

    1. Create a Slicer: Add a date slicer for users to select the date range.

    2. Add a Measure: Use this DAX formula to check active patients:

     

    ActivePatients = 
    CALCULATE(
        DISTINCTCOUNT(TableName[Patient]),
        TableName[Date] >= MIN('DateTable'[Date]),
        TableName[Date] <= MAX('DateTable'[Date]),
        TableName[Accepted] = "T"
    )

     

      1. Visualize: Add ActivePatients to your report to display active patients dynamically based on the selected date range.