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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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)))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.