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
NikkiSavage
Helper II
Helper II

Calculate count rows with all except and filter

I have a data set and I am trying to calculate the number of instances of infections in the past 2 weeks by patient. I am using the below formula:

 

Infections in last 14 days = var today = today()

return
calculate(COUNTROWS('Infections Raw Data'),
allexcept('Infections Raw Data', 'Infections Raw Data'[Customer_Code]),
filter( all('Infections Raw Data'[CommencementDate].[Date]),
'Infections Raw Data'[CommencementDate].[Date] > today - 14 &&

'Infections Raw Data'[CommencementDate].[Date] <= today))

 

However, whilst this returns a 1 for every infection in the past 14 days, it also picks up other infections that a customer has had even if it is months ago. E.g. if patient ABC had an infection in January as well as in the last 2 weeks, it will state that there has just been 1 infection in the past 14 days for this customer which is correct. But because there is another line in the data set detailing the infection in January for that customer, a 1 is also returned for this line which I don't want.

 

I essentially just want to count the number of rows per patient for the last 14 days. E.g. If a patient has had 2 infections in the past 14 days, I want a 2 in each line detailing the infection (there is one line per infection) or if a patient has only had one infection in the past 14 days but one months ago, I want it to return a 1 just in the row for the infection in the past 14 days.

 

I have signed an NDA so cannot post data for confidentiality reasons. Hopefully the above explanation is sufficient for help.

Thanks.

1 ACCEPTED SOLUTION

Hi. Thanks for your reply. That just returns blank data so doesn't work. All good though as the client has now decided they don't need that for now. Thanks anyway.

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@NikkiSavage , Try like

 

Infections in last 14 days = var today = today()
return
calculate(COUNTROWS('Infections Raw Data'),
filter( all('Infections Raw Data'),
'Infections Raw Data'[CommencementDate] > today - 14 && 'Infections Raw Data'[CommencementDate] <= now() && 'Infections Raw Data'[Customer_Code] = max('Infections Raw Data'[Customer_Code]) ))

 

This on the basis of customer

Hi. Thanks for your reply. That just returns blank data so doesn't work. All good though as the client has now decided they don't need that for now. Thanks anyway.

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.