How to find directional roots of a tree using Excel?

前端 未结 1 1343
谎友^
谎友^ 2020-12-12 07:14

I have the following question. Thank you for helping

There is a tree with directional roots from bottom to top. How can find all connections (in pairs) by using Exce

相关标签:
1条回答
  • 2020-12-12 07:41

    Big Picture : Stage1 : list all possible pairs for each column | Stage2 : combine the pairs & remove duplicate | Stage3 : put result in the desired format (L & M list..)

    [[ Stage 1 ]]

    Idea : load the original list[A] > generate index# for L & M [B] > load L & M value using index# [C]

    Assuming the data is exactly located as per in table1 in Sheet. Do all these in Sheet2..

    [ Creating the template ]

    • type "choose" in A1

      type "list :" in D1

      type "how many item :" in A7

      type "how many possible pairs :" in A9

    put :

    =IF(LEN(OFFSET(Sheet1!$A$1,ROW()-1,$B$1-1))=0,"",OFFSET(Sheet1!$A$1,ROW()-1,$B$1-1)) in E1 and drag until E5
    

    table E1 is the "load the original list" [A] part.

    Then :

    =COUNT(E1:E5) in D7
    =COMBIN(D7,2) in D9
    

    Now, start part [B] : "generate index# for L & M"

    Then:

    • type "generate list" in A11

      type "#" in A13

      type 1 in A13

      type "L" in K13

      type "M" in L13

    put in these formulas :

    =IF(A14<$D$9,A14+1,"") in A15 and drag until A24
    

    then :

    =D7 in C13
    =C13-1 in C14
    
    =IF(COUNTIF($C$14:C14,C14)=C14,C14-1,C14) in C15 and drag until C24
    

    then :

    =$C$13-C14 in D14 and drag until D24
    =INDEX($E$1:$E$5,D14) in E14 and drag until E24
    
    =IF(E14<>E13,G13+1,G13) in G14 and drag until G24
    =COUNTIF($G$14:G14,G14)+G14 in H14 and drag until H24
    =INDEX($E$1:$E$5,H14) in I14 and drag until I24
    

    End of part [B], "generating the index#".

    Lastly..

    =IF(A14="","",E14) in K14 and drag until K24
    =IF(A14="","",I14) in L14 and drag until L24
    

    Column I&E is the [C] part, "load L & M value using index#" . Where column K&L is the 'cleaned' version

    Done creating the template.. for better comprehension.. do these..

    • type "use "how many item" value to generate "index #"" in C26

      type "sort the output list as per wanted format" in K26

      type "generate index #" in D27

      type "get L value from list using index #" in E28

      type "get item count from value list" in G30

      type "use "item count" value to generate "index #"" in H31

      type "get M value from list using index #" in I32

    [ Using the template ]

    To use, enter the column number 1 - 10 in cell B1, and the result is in K13 table..

    [ Note ]

    This is to generate pairs list for 1 column.. you may extend it another column, by doing the same in sheet3. Change the B1 (select column) value in sheet3 to see/manipulate the result/list in K13 table.

    Do it till finish & try to understand each part of the formula.., ask if u r stuck /(^_^)

    some ref :

    https://exceljet.net/index-and-match

    https://exceljet.net/excel-functions/excel-combin-function


    [[ Stage 2 ]]

    Idea : generate address for each sheet > use indirect() to load list as a combined list

    Steps : Copy the above to sheet3 and choose column 2 (column 1 in Sheet2).. then repeat.. Sheet4 > Column 5.. Sheet6 > Column 5 .. until Sheet10.. Now create Sheet11 and do these..

    • type "Sheet[x]" in A1

      type "2" in A2

      type "Column#" in B1

      type "1" in B2

      type "SheetAddrs" in C1

      type "AddrsOfColmnK" in E1

      type "AddrsOfColmnK" in F1

      type "how many pairs listed per column" in H1

      type "from" in J1

      type "1" in J2

      type "to" in K1

    Then :

    =A2+1 in A3 and drag until A10 =B2+1 in B3 and drag until B10 ="Sheet"&A2&"!" in C2 and drag until C10 =C2&"K:K" in E2 and drag until E10 =C2&"L:L" in F2 and drag until F10 =COUNT(INDIRECT(E2,TRUE)) in H2 and drag until H10 =J2+H2-1 in K2 and drag until K10 =K2+1 in J3 and drag until J10

    Using the above as input.. now generate the exact address for each pair in each column and load it..

    type "CombineColumnPairList" in M1

    type "Column#" in P1

    type "pair#" in Q1

    type "Gnerate-L-Addrs" in S1

    type "Gnerate-M-Addrs" in V1

    type "FinalLstWithDuplicate" in Y1

    type "L" in Z1

    type "M" in AA1

    =IF(N1<SUM(H:H),N1+1,"") in N2 and drag until N60
    =IF(N2="","",MATCH(N2,$J$2:$J$11,1)) in P2 and drag until P60
    =IF(N2="","",IF(P2<>P1,1,Q1+1)) in Q2 and drag until Q60
    =INDEX(C:C,MATCH(P2,B:B,0))&"K" in S2 and drag until S60
    =13+Q2 in T2 and drag until T60
    =INDEX(C:C,MATCH(P2,B:B,0))&"L" in V2 and drag until V60
    =T2 in W2 and drag until W60
    =INDIRECT(S2&T2,TRUE) in Z2 and drag until Z60
    =INDIRECT(V2&W2) in AA2 and drag until AA60
    

    Done with the full listing.. in column Z&AA


    [[ Stage 3 ]]

    Idea : from stage2 full list.. > use countif(), if 1, then the pair is unique > Use the "1" to generate another list, the unique pairs only.

    • type "[Stage 3] Find Unique" in AC1

      type "howmany unique?" in AG1

      type "FinalLstWithNoDuplicate" in AI1

      type "L" in AK1

      type "M" in AL1

    Then :

    =Z2&"-"&AA2 in AD2 and drag until AD30
    =COUNTIF($AD$2:AD2,AD2) in AE2 and drag until AE30
    =IF(AE2=1,AF1+1,AF1) in AF2 and drag until AF30
    =COUNTIF(AE:AE,1) in AG2
    =IF(AJ1<$AG$2,AJ1+1,"") in AJ2 and drag until AJ30
    =IFERROR(INDEX(Z:Z,MATCH(AJ2,AF:AF,0)),"") in AK2 and drag until AK30
    =IFERROR(INDEX(AA:AA,MATCH(AJ2,AF:AF,0)),"") in AL2 and drag until AL30
    

    Column AK&AL should be ur desired resutls.. ( :

    Note : Since you had get the logic of the formula/method.. then u know by now that depending on the input table size.. all the given formula are adjustable..

    hope it helps.

    0 讨论(0)
提交回复
热议问题