Mar 10 2021 03:46 PM
Dear colleagues
I still record Covid tests in an excel table
Name | Test Result | Test date |
Alan | negative | 01.01.2021 |
Bred | negative | 01.01.2021 |
Alan | positive | 01.02.2021 |
Cindy | positive | 01.01.2021 |
Bred | negative | 02.03.2021 |
Alan | negative | 01.03.2021 |
Cindy | not tested | |
Bred | positive | 05.03.2021 |
and the request is to get number of negative and positive people. The person is negative or positive based on his latest test. (so negative=1 (Alan from 1.3.), positive=1 (Bred from 5.3.), not tested =1 (Cindy from "not tested" row)
The table is used in a dashboard with slicer, so the result should also reflect the filtered table.
See attachment with details.
Thank You
Zdenek Moravec
Cesky Krumlov, Czech Republic
Mar 11 2021 02:56 AM - edited Mar 11 2021 02:57 AM
I assume you are on Excel 365. With that
I'd add Helper column to the table with formula
=IF([@[Test date]]="",99999,[@[Test date]])*AGGREGATE(3,5,[@Name])
It returns zero for hided by filter rows, 99999 if date is missed and Test date otherwise.
When number of employees
=COUNTA(UNIQUE( FILTER( T_Data[Name], T_Data[Helper])))
and number of positive employees
=SUM(
(MAXIFS(T_Data[Helper],T_Data[Name],T_Data[Name],T_Data[Helper],">0") =
IF(T_Data[Helper],T_Data[Helper],-1 ))*
(T_Data[Test Result]="positive")
)
Same for negative and not tested
Mar 11 2021 03:10 PM
Mar 12 2021 12:58 AM
Hi Zdenek,
Let assume we filtered the table on ACC
and let split our formula on parts
Here
=MAXIFS(T_Data[Helper],T_Data[Name],T_Data[Name])
returns max date from helper against each name in the table. For hided rows helper is zero, otherwise max of available dates for the name in row. Without that we will have only one max value for all names.
Next is helper column which we would like to compare with previous result and return 1 if dates are equal (i.e. date in helper is equal to max date for the name), otherwise zero.
But if simply compare these two arrays all hided rows also return 1 (0=0), thus we use IF() to change helper for hided rows on -1.
In addition, the part T_Data[Name],T_Data[Helper],">0" in formula is not needed, it is from my initial variant and I forgot to remove. Finally formula could be
=SUM(
(MAXIFS(T_Data[Helper],T_Data[Name],T_Data[Name]) =
IF(T_Data[Helper],T_Data[Helper],-1 ))*
(T_Data[Test Result]="positive")
)
Mar 13 2021 02:48 PM
Hello @Sergei Baklan
I have reached my Excel limit, I cannot get this mega formula. One new thing for me is, that a reference to a table returns 0 for the filtered rows. The rest I must probably repeat more and more times in a free time.
Anyway, the formulas add up the max's of filtered table perfectly and I have implemented it.
Last thing - I need to count the total number of positive and negative tests.
I tried to COUNTA FILTERed list with the criteria:
=COUNTA(FILTER(T_Data[Test Result];(T_Data[Helper])*(T_Data[Test Result]="positive")))
The problem is, when FILTER returns empty array, the result of COUNTA is 1, not 0 or error (see attachment)
Is there a solution with the new dynamic formulas or I must use the old formula from google?
Thank You very much
Zdenek Moravec
Mar 14 2021 06:22 AM
SolutionHi Zdenec,
Filtered rows - in Excel there are two functions which could ignore hided rows or columns - SUBTOTAL() and AGGREGATE(). To check if row is hided you need to use one of these functions. There are few variants, here we use AGGREGATE() within helper column.
Empty cell counting - sorry, I didn't think about that. If array is empty FILTER by default returns an error, and COUNTA doesn't care that's error or not, counts it as any other value. We may use third parameters in FILTER which will be returned in case of empty array, check if it is returned and take zero as final result, otherwise count number of values in returned array. Resulting formula
=LET(
visible, FILTER( T_Data[Name], T_Data[Helper],-1),
IF(INDEX(visible,1)<> -1, COUNTA(UNIQUE( visible)), 0)
)
Mar 14 2021 06:41 AM
Hello@Sergei Baklan
I was playing with the empty filter array and I got the idea to filter in a helper cell and then test this cell in the COUNTA. You did it with LET, next function to study for me. But I have a nice example to study on.
Thank You very much for all the support, without your effort I could not finish the task!
You are my Joker.
Zdenek
Mar 14 2021 08:15 AM
Zdenek, sure, in Excel everything could be done by several ways, select one which is more comfortable for you.
You are welcome and good luck with your project.
Mar 14 2021 06:22 AM
SolutionHi Zdenec,
Filtered rows - in Excel there are two functions which could ignore hided rows or columns - SUBTOTAL() and AGGREGATE(). To check if row is hided you need to use one of these functions. There are few variants, here we use AGGREGATE() within helper column.
Empty cell counting - sorry, I didn't think about that. If array is empty FILTER by default returns an error, and COUNTA doesn't care that's error or not, counts it as any other value. We may use third parameters in FILTER which will be returned in case of empty array, check if it is returned and take zero as final result, otherwise count number of values in returned array. Resulting formula
=LET(
visible, FILTER( T_Data[Name], T_Data[Helper],-1),
IF(INDEX(visible,1)<> -1, COUNTA(UNIQUE( visible)), 0)
)