Excel: Count Unique Dates for set of multiple criteria - excel

I have a large spreadsheet with many data columns and dates . Column B is the date column and there are multiple rows of duplicate dates with different data in the following columns. I'm trying to write a formula to give me a count of how many unique dates there were given different criteria. I did this formula entered as an array and it worked perfectly.
=COUNT(1/FREQUENCY(IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16),IF('NA Trades'!B:B<>"",'NA Trades'!B:B)),IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16),IF('NA Trades'!B:B<>"",'NA Trades'!B:B))))
I tried expanding on this and adding more criteria but it doesn't seem to be working and giving me a result of 0. This is the array formula I tried with the added criteria
'=COUNT(1/FREQUENCY(IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16)*('NA Trades'!DQ:DQ<-2.6),IF('NA Trades'!B:B<>"",'NA Trades'!B:B)),IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16)*('NA Trades'!DQ:DQ<-2.6),IF('NA Trades'!B:B<>"",'NA Trades'!B:B))))
Where did I go wrong with the second formula and how can I format this formula so I can continue to add more criteria?

Your formula seems to be working fine, are you sure you have the correct data in your newly added column? BTW, I would suggest that you use named ranges or a table - it's easier to read.

Related

Excel count Unique ID's between two dates + a distinct count of another column for each ID

I am struggling with an Excel formula. I am trying to count the number of Unique ID's between two dates (I have that formula working), but I also want to count the SignUpRoles for each unique ID that qualified between the two dates. I am using O365.
Here is how I am capturing the UserId counts in K10:14
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=K5,IF(Weartime13[RecordDate]<=J5,MATCH(Weartime13[UserId],Weartime13[UserId],0))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
Here is the worksheet I am working with: RDS_Report
Screenshot:
RDS Report Screenshot
So what I mean by adding another 'if' is that in L14 (for example) you would have
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
and in the next column that would change to M9 and N9:
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=M9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=N9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
I've filled in the last row:
EDIT
As noted by #JosWoolley, a structured reference would have been preferable to row(A5). I would suggest:
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(Weartime13[#Headers])),1))
But what if you want to pull these formulas across so that L9 changes automatically to M9 and N9 but it still references the same table columns? I had to look this one up and the answer is:
=SUM(IF(FREQUENCY(IF(Weartime13[[RecordDate]:[RecordDate]]>=$O5,IF(Weartime13[[RecordDate]:[RecordDate]]<=$J5,IF(Weartime13[[SignUpRole]:[SignUpRole]]=L9,MATCH(Weartime13[[UserId]:[UserId]],Weartime13[[UserId]:[UserId]],0)))),ROW(Weartime13[[UserId]:[UserId]])-ROW(Weartime13[#Headers])),1))
Formula for the last row using count & filter would be
=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J5)*(Weartime13[RecordDate]>=O5))))
for the total and
=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J5)*(Weartime13[[RecordDate]:[RecordDate]]>=$O5)*(Weartime13[[SignUpRole]:[SignUpRole]]=L9))))
pulled across for the SignUpRole breakdown, assuming UserId is numeric.
But what if you wanted a single formula that could be pulled both down and across for the whole range of dates and roles? This could be arranged as follows:
=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J$5)*(Weartime13[RecordDate]>=INDEX($K$5:$O$5,ROW()-ROW($9:$9))))))
for the total and
=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J$5)*(Weartime13[[RecordDate]:[RecordDate]]>=INDEX($K$5:$O$5,ROW()-ROW($9:$9)))*(Weartime13[[SignUpRole]:[SignUpRole]]=L$9))))
for the role columns.
Is there a simpler way of doing this whole thing? Maybe with pivot tables or perhaps power query, but that would be a separate answer :-)

Averaging data across multiple columns based on criteria (excel)

I have a spreadsheet (Office 365 Pro) that has numeric data in multiple columns. I want to average data in those columns if specific multiple criteria is met in other columns.
For example, one formula that is in use:
=AVERAGEIFS(K:K,C:C, ">=01/01/2021", C:C, "<=1/31/2021")
This formula works exactly the way I want, for the data specifically only in column K.
I want to accomplish what this formula does, but to include columns K through P, and not K only.
I tested a simple average formula which worked fine across multiple columns
=AVERAGE(K:P)
I can't figure out how to average data in all of those columns based on the criteria in my other formula.
If I simply change the column to average to:
=AVERAGEIFS(K:P,C:C, ">=01/01/2021", C:C, "<=1/31/2021")
I get a #VALUE error.
Any suggestions on how to accomplish this?
use FILTER:
=AVERAGE(FILTER(K:P,(C:C>=DATEVALUE("01/01/2021"))*(C:C<=DATEVALUE("1/31/2021"))))

Compare two excel tables based on unique key using formula

I have two tables with same column names in excel which are getting data from two different sources based on certain calculations. We need to compare data between those two tables based on ID column value which will be provided by user in A2. I have attached snapshot of sample tables. I did try using sumproduct (as you can see in K2, but it doesn't work if any of the cell values has #NA as it's value. Please keep in mind that calculations update data for only a particular id (one row only for each table). in this example, values for only the rows with ID 200 will be updated for these two tables.
If I change value from #NA to an integer, formula (in K2) would work. Now I was even thinking about using if(And(logic1,logic2...)) to compare cell to cell values,but I don't kow how would I use it when the placement of ID's in columns C and G can vary and won't necessarly be in the same row.
Formula used:
=IF(G2:G5=A2,IF(SUMPRODUCT((G2:G5=A2)*(H2:I5))-SUMPRODUCT((C2:C5=A2)*(D2:E5))=0,"Match","No Match"),"")
This may help get you started.
=IF(AND(IF($A$2=G3,VLOOKUP(G3,C3:E6,2,0),"")=H3,IF($A$2=G3,VLOOKUP(G3,C3:E6,3,0),"")=I3),"Match","No Match")
Try following array formula:
=INDEX({"No Match","Match"},1,IFERROR(--(MATCH(COLUMNS($C$2:$E$2),MMULT(--(INDEX($C$2:$E$5,MATCH($A$2,$C$2:$C$5,0),0)=$G$2:$I$5),TRANSPOSE(COLUMN($C$2:$E$2)^0)),0)>0)+1,0))
Array formula after editing is confirmed by pressing ctrl + shift + enter

Excel formula to show prices based on 3 different dates

What is the excel formula to do below:
1. lookup from three or more different rows of dates (Q,R,S)
2. lookup the corresponding prices from another table based on these dates
3. fill the correct price based on the dates of another table
Below is a snapshot of what i would like the final outcome
SAMPLE DATA
The following formula will work for your sample data. You will need to adjust the ranges to suit your needs. There are other formulas that will produce the same results. The formula was initially set up assuming that the index numbers and dates were unique in their reference tables.
=IFERROR(VLOOKUP($B4,$B$14:$E$19,AGGREGATE(14,6,COLUMN($Q$4:$S$8)/(C$3=$Q$4:$S$8),1)-COLUMN($Q$3)+2,0),"Date or Index not found")
The iferror portion displays an error message for you should the date or index value (1201...1206, etc) not be found in either table.

Excel Formula to Lookup multiple columns

I tried reading other questions on this matter, and everything is very specific to that person so it got pretty confusing...
Anyways, I was looking for a way to use VLOOKUP or Index Match to do the following (I've been trying but I keep running into errors or weird...long....formulas...):
I have 2 excel Sheets. One excel sheet has something like this:
(This is incomplete. I haven't put in prices yet, but I'm working on the formatting and formulas foremost. Just pretend there are prices in those empty cells :) )
The second excel sheet is this:
In the 2nd Sheet, F Column, I was trying to get a formula to match Sheet2ColumnE with Sheet1 Columns A,F,K,P,U & Z and return [depending on whether cell D is B or S] the single or bulk price for the specific item.
I've used the Index Match formula before, but it got tricky when I had to index multiple columns and match multiple columns. Is there a simple way to get this going? Or will I be looping IFs?
Thanks for assistance.
Here is the workbook. Or a sample of it...
Test.xml

Resources