Hierarchical auto-numbering (with three levels) in Excel - excel

What if we have a three-level hierarchy and need to enumerate only "B"s (according to the pattern), but some "C-"s interfere with "B"s.
Problem: to get column B result from a given column A.
A+
B 1
B 2
С-
B 3
A+
B 1
С-
B 2
A+
С-
B 1
B 2
B 3
P.S. The task arose from the need to enumerate complex hierarchy in Excel.
Imagine that A - level 1; B - level 2; C - level 3. (with some abuse of logic in the example above as C- in the pattern goes after A, which in practice is usually not the case).
The simple case of two-level hierarchy is shown here.

Easiest would be to add in two intermediary helper columns, the first of which we'll call column C. Here, we will count only which "A+" we're on, like so [starting at C2; C1 is hardcoded as 1]:
=IF(A2="A+",A1+1,A1)
This will increment every time a new row has "A+" in column A.
Then column D will track the highest # reached so far, for that iteration in column C [starting at D2; D1 is hardcoded at 1]:
=IF(A2="A+",0,if(A2="B",B2,D1))
This will restart at 0 for each new "A+", and for each "B" it will take the value shown in column B. Then for each "C", it will simply repeat the value from the row above (the previous "B" reached).
Finally you can put in your sort, as follows [starting at E1]:
=IF(A1="B",B1,"")
This will show BLANK for either "A+" or "C", and will show the B-count if column A = "B".

I also went with a helper column (as much as I detest them personally) to show the row of each A+
Put this in C1: =ROW(A1)
Put this in C2: =IF(A2="A+",ROW(A2),C1)
It uses an expanding range with a rebasable starting point. Drag down as far as your data goes.
Put this in B2: =IF(OR(A2="C-",A2="A+"),"",IF(A1="A+",1,MAX(INDIRECT("B" & C2 & ":B" & ROW(A1)))+1))
Drag down as far as your data goes.
Hope that helps. Here are the results I received:
A+ 1
B 1 1
B 2 1
C- 1
B 3 1
A+ 6
B 1 6
C- 6
B 2 6
A+ 10
C- 10
B 1 10
B 2 10
B 3 10

Related

how to reference a specific cell in a formula if other cells match a specific value

Thanks so much for looking at my question! I am trying to create a formula that subtracts a specific value from another formula. However, that specific value may change.
Example:
A B C D
1 1 100 =(2000 - ( if A = 1, i want to subtract the C value where B =1))
1 2 250
1 3 310
1 4 .
2 1
2 2 =((2000 - ( if A = 2, i want to subtract the C value where B =1))
2 3
2 4
3 1
3 2
3 3
3 4
(A,B,C,D are the columns)
Hopefully this makes sense! I am trying to subtract the C value that goes along with the B1 value for each different A.
I was thinking an index match of some sort but wasnt exactly sure how to do that when the A's change. Thanks so much in advance for help!
INDIRECT or INDEX functions can help you. See this answer.
Would something like a nested if function work for you here? For example:
=IF(A2=1,IF(B2=1,2000-C2,"Enter calculation if B2<>1"),"Enter calculation if A2"<>1)
If this works, then you can simply copy/paste the function down the rows in column D.

How to create a one to many relationship?

The title may be confusing/misleading; I'm frankly having trouble trying to say what I need in a concise manner.
I have 2 lists of distinct values in Excel.
List A:
1
2
3
List B:
C
D
E
I need to create a sheet that shows a one to many relationship where List A is the 'One' and list B is the 'Many'. So the result would be something like :
Ouput:
1 C
1 D
1 E
2 C
2 D
2 E
3 C
3 D
3 E
The results are not concatenated and are in their own cols/rows. Any suggestions?
Assuming list 1 is in A1:A3, list to is in B1:B3. Then in D1 put :
=IF(CEILING(ROW()/ROWS($A$1:$A$3),1)>ROWS($A$1:$A$3),"",INDIRECT("A"&CEILING(ROW()/ROWS($A$1:$A$3),1),TRUE))
and in E1 :
=IF(CEILING(ROW()/ROWS($B$1:$B$3),1)>ROWS($B$1:$B$3),"",INDIRECT("B"&IF(MOD(ROW(),ROWS($B$1:$B$3))=0,ROWS($B$1:$B$3),MOD(ROW(),ROWS($B$1:$B$3))),TRUE))
and drag both downwards.
Idea : Use row() to 'guide' how the which cell will indirect() address to. You can test the given mod() and ceiling function separately to 'examine' how the pattern works. [do ask if you didn't get it.] (:
please share if it works/not.

Excel Formula comparing two columns

Below is a sample of the data I have. I want to match the data in Column A and B. If column B is not matching column A, I want to add a row and copy the data from Column A to B. For example, "4" is missing in column B, so I want to add a space and add "4" to column B so it will match column A. I have a large set of data, so I am trying to find a different way instead of checking for duplicate values in the two columns and manually adding one row at a time. Thanks!
A B C D
3 3 Y B
4 5 G B
5 6 B G
6 8 P G
7 9 Y P
8 11 G Y
9 12 B Y
10
11
12
11
12
I would move col B,C,D to a separate columns, say E,F,G, then using index matches against col A and col B identify which records are missing.
For col C: =IFERROR(INDEX(F:F,Match(A1,E:E,0)),"N/A")
For col D: =IFERROR(INDEX(G:G,Match(A1,E:E,0)),"N/A")
Following this you can filter for C="N/A" to identify cases where a B value is missing for an A value, and manually edit. Since you want A & B to be matching here col B is unnecessary, final result w/ removing col B and C->B, D->C:
A B C
3 Y B
4 N/A N/A
5 G B
6 B G
7 N/A N/A
Hope this helps!

Making multiple copies of a cell and duplicating it for a list

I have a list of different names that I would like to duplicate each one by 3 copies of itself. For instance:
A
B
C
D
E
to the following:
A
A
A
B
B
B
C
C
C
D
D
D
E
E
E
How I would I accomplish this in excel? Can it be done in Excel?
There are SOOO many ways to do this... One way would be using something along the lines of the OFFSET() function like so:
Supposing your original list was in cells A1:A5, say. You could then put this formula where you want it:
=OFFSET($A$1,ROUNDDOWN((ROW(A1)-1)/5,0),0)
and drag it down for the 25 rows you want.
In essence, what you're saying is:
Offset cell A1 by ROUNDDOWN((ROW(A1)-1)/5,0) rows and 0 columns.
Looking at that ROUNDDOWN() function:
Row(A1) = 1 (Similarly, Row(A2) = 2, etc...
(Row(A1)-1) / 5 = 0/5 ; 1/5 ; 2/5 ; .....
Rounddowwn(...) means 0/5 to 4/5 becomes 0 ; 5/5 to 9/5 becomes 1 ; etc
Therefore, it will offset A1 by 0 rows and 0 columns 5 times then by 1 row and 0 columns for the next 5, etc.
Hope that makes sense :)
EDIT:
The original question asked for 3 copies of each value, not 5 - I'm leaving the answer as-is purposefully with this edit so someone else can see how to change it to any number of repetitions as wanted... All that would change would be:
=OFFSET($A$1,ROUNDDOWN((ROW(A1)-1)/3,0),0)
Simply, divide by 3 rather than 5 for that to occur...

How to increment value based on duplicates and grouping

I have three columns, and I need column C to increment if there is a duplicate in column B, but only if the data is in the same group in column A:
A B C
1 Group 1 AB123 1
2 Group 1 SD244 1
3 Group 1 AB123 1 * should be 2
4 Group 2 FF444 1
5 Group 2 CD444 1
6 Group 3 AB123 1 * should stay as 1
7 Group 3 AB123 1 * should be 2
So basically Since AB123 is found again in column B in row 3, C3 increments by one, but C6 doesn't because it's in a different group (and then C7 does again because it 's in the same group as C6).
When I use COUNTIF($B$1:B1, B1), it doesn't increment by grouping also. Anyone have any idea how do it?
**edit
got it to work: used countifs($A$1:A1, A1, $B$1:B1,B1)
Well, if you could sort it by Column A and then Column B, you could write some nested IF statements that, for C2 for example would be something along the lines of: C2 =IF(A2=A1,IF(B2=B1,C1+1,1),1) syntax might be slightly off, but I think that should get you close, but only if you do the double column sort, otherwise, I don't know any simple way to do it.
I have just been trying to do this in Office 2016 with my data in the table, I found the following worked:
=COUNTIFS(Table1[[#Headers],[COLUMN1]]:[#[ COLUMN1]],[#[ COLUMN1]],Table1[[#Headers],[ COLUMN2]]:[#[ COLUMN2]],[#[ COLUMN2]])

Resources