Counting Combination Pairs in Excel - excel

Alright, I have a spreadsheet that looks like this in the "B" column:
AAA
BBB
BBB
AAA
BBB
CCC
DDD
BBB
AAA
BBB
CCC
What I need to do is to count how many times "BBB" directly follows "AAA" (In this example 3 times)
Ive tried multiple things with =SumProduct like =SUMPRODUCT(COUNTIFS(K6:K10,{"AAA","BBB"})) but that returns the product of all "AAA's" and "BBB's" instead of just the number of AAA & BBB pairs. The best I could do is to use =countifs() but I cant see a way to do a forward lookup like =countifs("B:B","AAA","B+1:B+1","BBB")
Also, I should mention, I was hoping to use this somewhere in the formula "Table13[[#All],[Radio State]]." That way the formula would grow and shrink depending on the size of the table.
Does anyone happen to know if its possible to do this?
Thanks Guys,

You can 'offset' the range by a bit like this:
=COUNTIFS(A1:A10, "AAA", A2:A11, "BBB")
You can change the range accordingly.
With a table:
=COUNTIFS(Table13[[#All],[Radio State]],"AAA",OFFSET(Table13[[#All],[Radio State]],1,0),"BBB")

Related

How to find one of every values in excel

basically I want to list one of every value like this.
data I have:
aaa
aaa
bbb
aaa
ccc
bbb
ddd
ccc
ddd
aaa
the output that I want:
aaa
bbb
ccc
ddd
how can I do this?
I can't find anything on google because I don't know the right keyword to search.

Natural sorting in reverse?

I'm trying to sort a text file in this manner:
6 aaa
4 bbb
2 ccc
2 ddd
That is, each line sorted first in numeric descending order (the number indicates the number of occurrences of the word on the right), and if multiple words are repeated the same number of times, I'd like to have those words sorted alphabetically.
What I have:
6 aaa
4 bbb
2 ddd
2 ccc
When I try sort -nr | sort -V it kind of does what I want but in ascending order.
2 ccc
2 ddd
4 bbb
6 aaa
What's a clean way to accomplish this?
I think you just need to specify that the numeric reverse sort only applies to the first field:
$ sort -k1,1nr file
6 aaa
4 bbb
2 ccc
2 ddd
-k1,1[OPTS] means that OPTS only apply between the 1st and 1st field. The rest of the line is sorted according to global ordering options. In this case, since no other options were passed, this means the default lexicographic sort.
Maybe using tac? (not a shell expert here, just remembering uni days...
sort -nr | sort -V | tac

Excel Pulling Text within Cells

So I have a cell that contain this text string. I was wondering if I can pull the text between from and upon. So it captures AAA (being varying degree of length)
life insurance policy #111 111 111 for the amount of $500,000.00 from AAA upon the life of xxx
So far I only managed this:
=MID(STP_Data!D71,FIND("from",STP_Data!D71), 42)
But if the text length changes it wouldn't capture it. Also how would I not capture from within my formula. Since my currently formula will include 'from' when it is pulled. Thanks guys!
How does this work?
=Trim(SUBSTITUTE(MID(A1,SEARCH("from",A1),SEARCH("upon",A1)-SEARCH("from",A1)),"from",""))
Edit: Added TRIM() per Scott's suggestion.

Is there some kind of option to merge Excel files by column IDs?

What I mean is, if I have:
f1.xls
Product ID / Product Name
1 / 12
2 / 13,64
f2.xls
Name_ID / Name_Val
12 / aaa
13 / bbb
64 / ccc
Can I somehow merge them to:
Product ID / Product Name
1 / aaa
2 / bbb / ccc
?
If you have several values in one cell separated by a comma, as your "Product name" data sample suggests, it will be very difficult to process with a formula. You will need to provide more than just a data sample like the above.
It also looks like you expect several values as output in one cell. Again, this is not easily accomplished.
I suggest that you step back from constructing hypothetical solutions that are based on assumptions that may or may not be met by Excel.
Instead, please explain the bigger picture. What are you trying to achieve? That is not "Merge the two files". What is the reason that makes you want to merge the files?
My answer will probably be shot down because I'm only asking questions for clarification and not providing a 'real' answer, but in order to even get started on your question, you need to provide a lot more background and I did not want to do this with comments.
Post more detail about your real situation. Post the bigger picture. Edit your question and provide that detail.

Excel parent list chain

I have a large table of two columns in Excel 2010. Column A is the user, column B is the person who invited the user. Usernames are alphanumeric, including some which are just numeric. The earliest users don't have an invitee.
User | Parent
-------------
AAA |
BBB |
CCC | AAA
DDD | BBB
EEE | DDD
FFF | DDD
GGG | FFF
HHH |
III | GGG
What I would like to do is have a formula which allows me to go to grandparent (and great-grand-parent, and beyond), so I'm trying to find a formula-based solution which uses mixed relative and absolute columns where appropriate.
The above chain would go to a maximum of four, but I have reason to believe my data set goes to no more than 20 levels deep at maximum. I would like to find a formula or combination of formulas that get me to this (and, as I said, beyond):
USER | PARENT | P2 | P3 | P4 | ...
AAA | |
BBB | |
CCC | AAA |
DDD | BBB |
EEE | DDD | BBB |
FFF | DDD | BBB |
GGG | FFF | DDD | BBB
HHH |
III | GGG | FFF | DDD | BBB
...
I've tried various methods combining VLOOKUP, MATCH, and INDEX commands, with and without a key row of user ID numbers (since some of those solutions without a numeric column broke down when faced with the fact that "0" was a valid username, which makes error trapping more difficult). I can get to P2 pretty reliably, but I can't ever seem to get to P3 without it breaking down. Incidentally, the formulas I've tried are very CPU-intensive, given the data goes to nearly 400,000 rows, but calculation time doesn't concern me much. My brute-force methods aren't working. There are several somewhat similar questions on stackoverflow, but they're asking for slightly different things, and I haven't been able to adapt any of them.
If this can be done via standard functions, that would be preferable to VBA (which I am not familiar with), even if the calculation time is longer, as it would increase my ability to maintain it when I need to revisit this issue next year.
Try this formula:=IFERROR(VLOOKUP(C5,UserParent,2,FALSE) & "",""), replacing UserParent with your absolutely referenced column pair (e.g. $B$5:$C$30) or an appropriate named range. Copy it down and across your grandparent columns.
I'm betting this is the approach that you tried before, but you end up with a bunch of zeroes in the output. The juicy bit in this formula is the & "". This forces the empty cells in your parent column to be treated as empty strings rather that zero-valued cells when VLOOKUP does its work. This removes all those zeroes that dork up the output.
I was able to make it work with a bunch of random alphanumerics, but without sample data, this is the best I could do.
As you have noted, the existence of 0 as a valid username, is a real problem - since this also gets returned as a value by VLOOKUP() (and equivalently by INDEX(,MATCH())) for names with no parents.
An alternative strategy is to use some dummy value which does not appear in either the User or Parent column, such as -99999, to signify the absent parent and to add this in place of any empty cell in the Parent column of the User/Parent table. Also add a row to this table with this same dummy value in both the User and Parent columns. Now you will only get a zero returned by VLOOKUP if 0 is genuinely the parent of the cell whose parent you are attempting to find. You will detect when there are no more "levels" when all the values in the column are equal to the dummy value.

Resources