Jan 23 2024 06:51 PM
I have Column A with many servernames which are often duplicated.
Column B has a variety of dates.
I want to count the number of unique servers for a specified date.
e.g. I have this:
server1 | 1-Feb |
server1 | 1-Feb |
server1 | 1-Feb |
server2 | 1-Feb |
server3 | 2-Feb |
server3 | 2-Feb |
server4 | 2-Feb |
server4 | 2-Feb |
server4 | 2-Feb |
server4 | 2-Feb |
server5 | 2-Feb |
server5 | 2-Feb |
I want to count the unique number of servers for 1-Feb and the unique number of servers for 2-Feb.
The date cells are formatted as dates so although the cell shows 1-Feb, the cell data is actually 1/02/2024.
Please can someone help advise the combo of functions which will do this?
Jan 23 2024 08:04 PM
@JennyMarfell-Jones You may try the following formula-
=HSTACK(UNIQUE(B1:B12),MAP(UNIQUE(B1:B12),LAMBDA(x,ROWS(UNIQUE(FILTER(A1:A12,B1:B12=x))))))
Jan 23 2024 11:01 PM
Solution@JennyMarfell-Jones To return a distinct count of server names for a specified date, the SUM / COUNTIFS method can be used with the UNIQUE function (Excel 2021 or later). For example, if the input cell for the specified date is cell D2, the following formula can be used:
=SUM(IF(COUNTIFS(B2:B13, D2, A2:A13, UNIQUE(A2:A13)), 1))
With Excel for MS365 (or Excel for the Web), you can also create a summary report for all dates in the dataset using the HSTACK and BYROW functions:
=LET(arr, UNIQUE(B2:B13),
HSTACK(arr, BYROW(arr, LAMBDA(r,
SUM(IF(COUNTIFS(B2:B13, r, A2:A13, UNIQUE(A2:A13)), 1))))))
Alternatively, the ROWS / FILTER method can be used for a specified date:
=LET(data, UNIQUE(A2:B13), incl, DROP(data,, 1)=D2,
IF(OR(incl), ROWS(FILTER(data, incl)), 0))
Or, to create a summary report for all dates in the dataset:
=LET(a, UNIQUE(A2:B13), b, DROP(a,, 1), c, UNIQUE(b),
HSTACK(c, BYROW(c, LAMBDA(r, ROWS(FILTER(a, b=r))))))
Please see the attached workbook, which contains all of the examples shown above...
Jan 29 2024 01:33 PM
Hi Harun, that's awesome, thanks for responding and helping out! Will try that out!
Cheers
Jenny
Jan 29 2024 01:34 PM
Jan 23 2024 11:01 PM
Solution@JennyMarfell-Jones To return a distinct count of server names for a specified date, the SUM / COUNTIFS method can be used with the UNIQUE function (Excel 2021 or later). For example, if the input cell for the specified date is cell D2, the following formula can be used:
=SUM(IF(COUNTIFS(B2:B13, D2, A2:A13, UNIQUE(A2:A13)), 1))
With Excel for MS365 (or Excel for the Web), you can also create a summary report for all dates in the dataset using the HSTACK and BYROW functions:
=LET(arr, UNIQUE(B2:B13),
HSTACK(arr, BYROW(arr, LAMBDA(r,
SUM(IF(COUNTIFS(B2:B13, r, A2:A13, UNIQUE(A2:A13)), 1))))))
Alternatively, the ROWS / FILTER method can be used for a specified date:
=LET(data, UNIQUE(A2:B13), incl, DROP(data,, 1)=D2,
IF(OR(incl), ROWS(FILTER(data, incl)), 0))
Or, to create a summary report for all dates in the dataset:
=LET(a, UNIQUE(A2:B13), b, DROP(a,, 1), c, UNIQUE(b),
HSTACK(c, BYROW(c, LAMBDA(r, ROWS(FILTER(a, b=r))))))
Please see the attached workbook, which contains all of the examples shown above...