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 September 15. Request your voucher.

Reply
Anonymous
Not applicable

Percentage Positive by Date

Hello,

 

I would like to create a DAX measure that calculates the positiviy rate by date.  Positivity Rate=Positive Cases per day/Total Tests Performed per day

My table has the following headers: Column Names.png

 Result 2 is where the data is located that I wish to describe. 

Draw date is the date I wish to use for the calculation. 

 

Could you help me write a DAX that I can use to count the number of tests performed in a day as well as the number of positive tests that were also reported in that day?

 

Thanks

 

I have the following relationship table formed:

Relationship Table.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

For the total number of tests performed your measure should count the total rows of patients tested which would look something like this: 

[Total Tests] =
CALCULATE(DISTINCTCOUNT('Raw Data'[Patient ID]), FILTER('Raw Data', 'Raw Data'[Patient vs Non-Patient] = "Patient")

This measure counts the unique number of patients ID's in your data, filtering to make sure they are a patient (assuming you want patients only).

For positivity rate it would be something like this: 

[Positivity Rate] = 
VAR _positive = CALCULATE([Total Tests], FILTER('Raw Data', 'Raw Data'[Result 2] = "Positive")
VAR _result = DIVIDE(_postive, [Total Tests])
RETURN _result

This measure uses variables to calculate the positivity rate. It uses the same measure for total tests but adds an additional filter to the data so that we only count the positive results. In this instance I'm using it as a variable but you can use the same formula for another measure to get the # of positive cases. 

These measures rely on the filter context of visuals. That means when you use the 'Date Table'[Date] column, it will give you the numbers for that specific date. 



View solution in original post

3 REPLIES 3
Anonymous
Not applicable

For the total number of tests performed your measure should count the total rows of patients tested which would look something like this: 

[Total Tests] =
CALCULATE(DISTINCTCOUNT('Raw Data'[Patient ID]), FILTER('Raw Data', 'Raw Data'[Patient vs Non-Patient] = "Patient")

This measure counts the unique number of patients ID's in your data, filtering to make sure they are a patient (assuming you want patients only).

For positivity rate it would be something like this: 

[Positivity Rate] = 
VAR _positive = CALCULATE([Total Tests], FILTER('Raw Data', 'Raw Data'[Result 2] = "Positive")
VAR _result = DIVIDE(_postive, [Total Tests])
RETURN _result

This measure uses variables to calculate the positivity rate. It uses the same measure for total tests but adds an additional filter to the data so that we only count the positive results. In this instance I'm using it as a variable but you can use the same formula for another measure to get the # of positive cases. 

These measures rely on the filter context of visuals. That means when you use the 'Date Table'[Date] column, it will give you the numbers for that specific date. 



amitchandak
Super User
Super User

@Anonymous , Not very clear with model.

You have to try like

divide(calculate(countrows(RawData), filter(resultlist, resultlist[result] ="Positive")) ,calculate(countrows(RawData)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
jthomson
Solution Sage
Solution Sage

Well, I'm assuming that measure "positive cases" is counting up something in the raw data based on some criteria that indicates that a case is positive. Make another measure that's basically the same except without that criteria, then another dividing one by the other

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.