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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Claus_Vad
Frequent Visitor

Need to calculate number of active cases at any date

Hi there
I need to calculate number of active cases at any date, and show them in a line chart

Have a fact table with around 2,500,000 records/cases, dates mostly opening days monday - friday, but want to show for all days

Every case has a start date and a end date (if the case is closed)

Any sugestions?

Regards Claus

2 ACCEPTED SOLUTIONS
v-cazheng-msft
Community Support
Community Support

Hi @Claus_Vad,

 

You need a calendar table firstly, and you could create it by a Calculated table.

Calendar =
VAR minDate =
    MIN ( 'Fact Table'[start date] )
VAR maxDate =
    TODAY ()
RETURN
    CALENDAR ( minDate, maxDate )

 

Then, you need a Measure to count cases.

Active Case Number =
VAR num =
    CALCULATE (
        COUNT ( 'Fact Table'[case] ),
        FILTER (
            'Fact Table',
            'Fact Table'[start date] <= MAX ( 'Calendar'[Date] )
                && ISBLANK ( 'Fact Table'[end date] )
        )
    )
RETURN
    IF ( ISBLANK ( num ), 0, num )

 

The result looks like this.

vcazhengmsft_0-1659063727193.png

 

Also, attached the pbix file.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,                                             

Community Support Team _ Caiyun

View solution in original post

Hi @v-cazheng-msft 

Thanks for your sugestion 

It was almost right, this will do what I want 

Active Case Number =
VAR num =
CALCULATE (
COUNT ( 'Fact Table'[case] ),
FILTER (
'Fact Table',
'Fact Table'[start date] <= MAX ( 'Calendar'[Date] )
&& ('Fact Table'[end date] > min('Calendar'[Date])
|| ISBLANK ( 'Fact Table'[end date] ))
)
)
RETURN
IF ( ISBLANK ( num ), 0, num )

View solution in original post

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi @Claus_Vad,

 

You need a calendar table firstly, and you could create it by a Calculated table.

Calendar =
VAR minDate =
    MIN ( 'Fact Table'[start date] )
VAR maxDate =
    TODAY ()
RETURN
    CALENDAR ( minDate, maxDate )

 

Then, you need a Measure to count cases.

Active Case Number =
VAR num =
    CALCULATE (
        COUNT ( 'Fact Table'[case] ),
        FILTER (
            'Fact Table',
            'Fact Table'[start date] <= MAX ( 'Calendar'[Date] )
                && ISBLANK ( 'Fact Table'[end date] )
        )
    )
RETURN
    IF ( ISBLANK ( num ), 0, num )

 

The result looks like this.

vcazhengmsft_0-1659063727193.png

 

Also, attached the pbix file.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,                                             

Community Support Team _ Caiyun

Hi @v-cazheng-msft 

Thanks for your sugestion 

It was almost right, this will do what I want 

Active Case Number =
VAR num =
CALCULATE (
COUNT ( 'Fact Table'[case] ),
FILTER (
'Fact Table',
'Fact Table'[start date] <= MAX ( 'Calendar'[Date] )
&& ('Fact Table'[end date] > min('Calendar'[Date])
|| ISBLANK ( 'Fact Table'[end date] ))
)
)
RETURN
IF ( ISBLANK ( num ), 0, num )
Claus_Vad
Frequent Visitor

Hi @tamerj1

a case is active when it have a startdate and enddate is blank

tamerj1
Super User
Super User

Hi @Claus_Vad 
Please define your business logic of "active cases". Thank you

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors