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

Count number of active cases over time based on date rangeundefined

Hi

 

I'm trying to calculate the number of active cases over timer based on a date range between two dates; the date that the case was opened and the dates that the case was closed (if the case hasn't been closed yet the closed date will be blank and therefore the case is still open).

 

Example of the data:

ID           Open           Closed

1             1/1/2018     1/12/2018

2             1/4/2018     1/12/2018           

3             2/1/2018     2/14/2018

4             2/13/2018   2/13/2018

5             1/1/2018     1/14/2018

 

So on the 1/5/2018 there are 3 active cases. This is an example pr. day. For the week I want to see the average of open cases for the days included in that week. The same for the month and year.

 

I hope that someone has a brilliant solution to this. 

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @camgyl 

Create a visual control measure as below:

visual control =
VAR selected_date =
    SELECTEDVALUE ( 'Calendar Date'[Date] )
VAR flag =
    IF (
         (
            selected_date > SELECTEDVALUE ( 'Table'[Open] )
                && selected_date < SELECTEDVALUE ( 'Table'[Closed] )
        )
            || (
                selected_date > SELECTEDVALUE ( 'Table'[Open] )
                    && SELECTEDVALUE ( 'Table'[Closed] ) = BLANK ()
            ),
        1,
        0
    )
RETURN
    IF ( ISFILTERED ( 'Calendar Date'[Date] ), flag, 1 )

 

Them apply it to table visual filter pane :

35.png

 

Create measure "count" then apply it to a card visual:

Count =
VAR selected_date =
    SELECTEDVALUE ( 'Calendar Date'[Date] )
VAR tab =
    SUMMARIZE (
        FILTER (
            ALL ( 'Table' ),
             ( selected_date > 'Table'[Open]
                && selected_date < 'Table'[Closed] )
                || (
                    selected_date > 'Table'[Open]
                        && 'Table'[Closed] = BLANK ()
                )
        ),
        'Table'[ID]
    )
RETURN
    COUNTX ( tab, [ID] )

 

The result will show as below:
39.png

Please check attached pbix file for more details.

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

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.