Excel formula count after certain observation in c horological order - excel

I am having tough time building a logic around this problem for a while , Hope some one can help.
I have 3 column of data. Lets call them Customer ID , Call ID , Agent ID
Customer ID and Agent ID can have repetition however Call ID is unique .
Now i have a table with these columns- they are stacked in chronological order based on date or time. Also one customer can call multiple time to multiple agent generating unique caller ID every time.
Here i want to count number of time one customer has called after certain agent ID has received the call. So count or freq function will have to have a rule embedded in chronological function or "Count after certain rule has been met"
Below is the table
CusID CalID Agent
1 123 a
1 22 b
1 112 a
1 222 a
1 54 a
1 334 a
2 221 a
2 312 b
2 334 b
2 129 b
2 986 a
4 98 b
In above table i want to calculate number of observation for customer id '1'after he has called to agent 'b' so the answer will be 4. I have used couple of unique count based no multiple crietria using combination of sumif 1/countif however major problem is counting after certain observation.
can any one help

You can use this formula that will change the range to count to match where b is found the first time.
=COUNTIF(INDEX(A:A,AGGREGATE(15,6,ROW($C$2:$C$13)/(($C$2:$C$13=E3)*($A$2:$A$13=E2)),1)+1):$A$13,E2)

Related

How do I retrieve value in Column B Given 2 Criteria on the Same Row in an excel Formula

I have a table similar to the one below and am trying to get column B data based on the criteria in Column A and C. A = UserID, B = Description, C = Cost_Priority, D Cost. The table lists each userID, and common problem description, ranking the cost for the problem description and the cost of the problem description. This is a supplied table that I am working from.
UserID
Problem_Description
Cost_Priority
Cost
111
Problem A
1
395.00
111
Problem B
2
200.00
111
Problem C
0
150.00
111
Problem D
0
145.00
112
Problem G
1
800.73
112
Problem S
2
200.46
112
Problem T
0
100.51
Resulting Table should look like the one below where UserID is Given along with the columns
that define the Cost Priority Required. The problem I am having is getting the problem description
based on static values in the User ID columns static values of 1 for Highest cost problem and 2 for the 2nd highest cost problem.
UserID
Highest Cost Problem
2nd Highest Cost Problem
111
Problem A
Problem B
112
Problem G
Problem S
I have tried using a vlookup method to grab the USERID and compare Cost_Priority to 1 or 2 in an if statement but it was returning the Problem Description column in order including where Cost Priority was 0. I was wondering if someone else had any other ideas to populate the 2nd and 3rd columns in the 2nd table.
If you are on Microsoft 365 then try below formula. Drag down and across as needed.
=INDEX(SORT(FILTER($B$2:$C$8,($A$2:$A$8=$A12)*($C$2:$C$8>0)),2,1),COLUMN(A$1),1)
For older versions of excel try below array formula-
=INDEX($B$2:$B$8,MATCH(1,($A$2:$A$8=$A12)*($C$2:$C$8=COLUMN(A$1)),0))
Press CTRL+SHIFT+ENTER to evaluate the formula as it is an array formula.

how to count distinct values in excel for a matrix form

I have looked if this has been asked, but could not find out exactly.
I' ve been trying to count distinct values.
I tried sumproduct,sum(1/countif) etc, so far I got nothing but a div error or 0.
Basically, I' ve two columns: Campaign_no and customer_id.
what I need is count unique customers for each campaigns and count unique customers that appears in the campaigns at the same time, sort of matrix.
The table is as follows:
Campaign_no
Cust_id
A
1
A
2
A
2
B
1
B
4
B
5
B
9
C
4
C
5
C
6
C
7
What I need is below:
Campaigns
A
B
C
A
2
1
0
B
1
4
2
C
0
2
4
As you see Campaign A has 2 unique customers, so A-A cell is 2.
Campaign A and B have one customer in common, so A-B cell is 1.
Campaign A and C have no common customer, this box got 0.
Campaign B and C has 4 unique customer on their own,
but they have two common customers, so B-C box has 2 ( if those customers were the same, it would have been 1) .
Is there way of calculating this without vba or PT? I'm using Excel 2017.
Much appreciated.
Here is a solution using helper cells.
C2 is =A2&B2. Copy it to C3:C12.
D2 is =IF(ISNA(MATCH(B2,D1:$D$1,0)),B2,""). Copy it to D3:D12.
E2 is =IF($D2="","",1-ISNA(MATCH(E$1&$D2,$C$2:$C$12,0))). Copy it to E2:G12.
E15 is =SUMIFS($E$2:$E$12,E2:E12,1). Copy it to F15:G15.
E16 is =SUMIFS($F$2:$F$12,E2:E12,1). Copy it to F16:G16.
E17 is =SUMIFS($G$2:$G$12,E2:E12,1). Copy it to F17:G17.
You may be able to get away without using the helper column C in Office 2017. I only have Office 365, so I couldn't it correctly.
Here's one that you could try, but it assumes that the data is sorted into contiguous blocks in alphabetical order of campaign exactly as shown in the sample data:
=SUMPRODUCT((COUNTIFS($A$2:$A$12,F$1,$B$2:$B$12,INDEX($B$2:$B$12,MATCH($E2,$A$2:$A$12,0)):INDEX($B$2:$B$12,MATCH($E2,$A$2:$A$12,1)))>0)
/COUNTIFS($A$2:$A$12,$E2,$B$2:$B$12,INDEX($B$2:$B$12,MATCH($E2,$A$2:$A$12,0)):INDEX($B$2:$B$12,MATCH($E2,$A$2:$A$12,1))))
The idea is that you use countifs to check through each customer ID in campaign A (for example) to see if it's present in campaign B. But it's possible that a customer ID appears more than once in campaign A, so you still have to divide by the count of each customer number in campaign A to get the unique count.

DAX returning value based on SUM of multiple rows in other table

Good evening all!!
Here's a fun one. I've been pouring through some other posts and it feels like there are many permutations of this scenario but none that span tables, so I'm looking for some input.
Consider the following:
Table A has two fields: ID and TYPE. TYPE will be our value to populate.
ID Type
1
2
3
Table B has two fields: ASSOCIATED ID and HOURS.
Associated ID Hours
1 24
1 0
2 10
2 38
3 50
3 25
The requirement is to return a value of "LESS THAN 25" or "GREATER THAN 25" for TYPE in TABLE A based on the SUM of the HOURS in TABLE B for the ASSOCIATED ID. Ex: ASSOCIATED ID "1" in TABLE has value 24 and 0 for a sum of 24, returning "LESS THAN 25" for TYPE in item ID 1 in TABLE A.
Any and all suggestions will be attempted, thank you so much to the community for taking a look.
Make sure you have a relationship between the two tables by using the ID. Then enter this formula into a column in the ID table:
Type:=if(calculate(sum(TableB[Hours]))>25,"25 or More","Less than 25")
Try this one on 1-TYPE: (I am considering A1 Cell as the beginning of your table for both table, just place the real position)
=IF(SUMIF(TableB!$A$2:$A$7,"="&A2,TableB!$B$2:$B$7)>=25,"GREATER THAN 25","LESS THAN 25")
Then drag it down.

Index/match with two criteria anyway to get the second set of data using unique identifiers?

I've been stuck for some time trying to match up two different data spread sheets. I'm trying to match off dollar amounts with matching names that correspond to the dollar amount. I went ahead and assigned unique identifiers to each row thinking that would help me match off the amounts, but my problem comes when there are two or more dollar amounts that are the same and have the same name.. is there anyway to get the second id to show up?
Formula sheet: (I need The second 112 to pull 113.. anyway thats possible??
A B C D E F G
IDSheett2 IDsheet1 NameSheet1 NameSheet2 Item AmountSheet1 AmountSheet2
554 112 Jim Jim Hat 25 25
555 112 Jim Jim Shoe 25 25
Formula in column B2: it should go through both sheet 1 and 2 and automacially fill in the matching id - id that matches the name and amount.
=IFERROR(INDEX(sheet1!$C$2:$C$1000,MATCH(1,INDEX((sheet1!$A$2:$A$1000=D1)*(sheet1!$B$2:$B$1000=G1),0,1),0)),"")
Data from Sheet2:
A= ID B= Name C= Item Name ( ID basically row 1 = 1, 2 = 2.. )
A B C D
554 Jim Hat 25
555 jim Shoe25
Data from Sheet1:
A= name B= amount C= assigned ID ( ID basically row 1 = 1, 2 = 2.. )
A B C
Jim 25 112
Jim 25 113
I'm also open to other ideas. Thanks for the help.
UPdated::: Based on comments
im not trying to create a database.. i have two sets of data that i'm trying to compare and match off like items(i take matched items and email it out to a group of people). i had to change some of the names because this is work related but the overall concept should remain.
it is Impossible for me to know how many names will be on incoming wires and how many names will be on my expected wires lists. I assigned unique ids per row on each page so i can do iferror/index/match to pull from a unique row to the main page.
What im trying to accomplish:
I have two sets of data: Sheet1 is incoming wires (it gives me a name and an amount) Sheet 2 is the account name, Item its for, and expected amount.
I'm trying to match the name and amount on the formula sheet but i run into the problem of two items with the same name and the same amount only pulling the first ID number it runs into and this becomes a problem because i have another vba code that will delete multiple ID's so i know i'm not counting something twice.
my final page should read:
ID sheet2 IDsheet1 Name Item(sheet2) Amount
554 112 JIM Hat 25
555 113 JIM Shoe 25
but right now the 113 id wont pull and it will just be 112 twice (which will end up getting deleted so i will miss that second match)
..+ everything works perfectly unless there are two items for the same name and the same amount +.. that is the only time i run into this problem.
Is there any code or process that can have the sheet realize that it has already used the ID of 112 once and then automatically fill in the id of 113 (so it won't get deleted by my vba code)?
In your formula sheet, B2 and copied down:
=IFERROR(INDEX(Sheet1!$C$2:$C$1000,MATCH(1,INDEX((Sheet1!$A$2:$A$1000=D2)*(Sheet1!$B$2:$B$1000=G2)*(COUNTIF(B$1:B1,Sheet1!$C$2:$C$1000)=0),),0)),"")

How to only count unique record once and based on that count Yes or No

I have 3 columns
ORDER, ID and E Yes/NO
In Column C order
In Column D ID
In Column E Yes/No
For example for ID = 144. I need count to how many order it was given to 144.
so looking at sample table below 144 was given 1 order which was 821 and column is Yes for 144 and when Order = 821.
Another example ID=162.
was given 2 order , 861 and 992. so his total order count is 2 and # of Yes count is 1 because row 13 is No.
I am really stuck on this complex logic.
Any feedback would be appreciated.
Given the layout shown, try these in B17 and C17 respectively, then fill down:
=SUM(IF(FREQUENCY(IF(MMULT(-(D$2:D$13=A17),1),C$2:C$13),C$2:C$13),1))
=SUM(IF(FREQUENCY(IF(MMULT((D$2:D$13=A17)*(E$2:E$13="YES"),1),C$2:C$13),C$2:C$13),1))

Resources