excel-formula

Create string of text with Textjoin, dependent on a selection from DropDown


I need to populate a cell with a string (textjoin?). The string should contain the unique Price Art. And its percentage of the total, from columns, dependent on a selection made in a drop down list.

  1. I have a limited different "Type of work": PM, Engineering, Enabling works...
  2. I have 1-4 supplier quotes
  3. Each supplier quotes will be broken down into "Type of Works" and Price Art. (Price Art will differ in code and number)

  1. Input the name of a supplier
  2. Based on the quote, for each Type of work, break the Cost down into Price Art.
  3. Type of work in Col. A,
  4. Cost in Col C,
  5. Price Art. in Col D
  6. Repeat from 1 for next Supplier...
  7. When all quotes are done - The "tool" should, dependent on the Supplier selected, create a string for each "Type of work", with the percentage of the total for each Price art. and Type of works..

A11 - A18 - A... : Input the Type of Works (Drop-Down list connected to C1:K1

C9: First supplier name

E9: Second supplier name...

C11 - C18 - C...: Input the Cost for Supplier one, according to the Type of work, and Price Art., obs Type of works can have different price Art.

Repeat for all columns - E-J....

C2:K2 : For the selected Supplier in B2, and all Unique "Type of works" in Col A, calculate the % for each price art of the Type of work... (See C2)

enter image description here


Solution

  • =LET(range,A9:G18,
         c,CHOOSECOLS,
         d,DROP,
         u,UNIQUE,
         header,d(TAKE(range,1),,-1),
         h,TOCOL(header,1),
         data,d(range,1),
         f,LAMBDA(a,b,FILTER(a,header=b)),
         j,TOROW(u(c(data,1))),
    HSTACK(u(TOCOL(h)),
           REDUCE(u(d(j,,1),,1),d(h,1),LAMBDA(k,l,
           VSTACK(k,
                  MAP(d(j,,1),LAMBDA(m,
                      LET(g,GROUPBY(f(d(data,,1),l),f(d(data,,-1),l),PERCENTOF,,0,,c(data,1)=m),
    TEXTJOIN("; ",,IFERROR(ROUND(c(g,2)*100,)&"% "&c(g,1),"-"))))))))))
    

    Where range is your input range starting at column A from where your supplier data starts (including headers).

    c is ETA to use the letter as the function CHOOSECOLS(), d for DROP() and u for UNIQUE().

    header is taking the header values from the input range, excluding the final cell value (of merged cell).

    h takes out the empty cells from headers.

    data is your input range excluding the header row.

    f is a FILTER function to filter input range a where the header value equals B2.

    j is the first column values of data

    g creates a percentage summary on filtered Price Artikel and it's Cost where the first column values from data equals the value of the header value in row 1.

    Next the columns of g are concatenated and wrapped in TEXTJOIN for each Type of work using MAP and for each Name supplier using REDUCE.

    enter image description here

    Sample of data I used for testing, where supplier 1 and supplier 2 are merged cells:

    A B C D E F
    9 Name supplier Supplier 1 Supplier 2
    10 Type of work work description cost price artikel cost price artikel
    11 PMT 100 aaa 23 aaa
    12 PMT 50 sss 3465 sss
    13 ENG 43 ddd 1234 ddd
    14 Civil works 23 sss 5467 fff
    15 Civil works 56 ddd 3453 qqq
    16 Trials 234 qqq 3245 rrr
    17 PMT 150 aaa 56 fff
    18 PMT 75 ttt 456 ttt

    EDIT: Here's a version that avoids the use of GROUPBY:

    =LET(supplier,TOCOL(C9:J9,1),
         work,UNIQUE(TOROW(A11:A39,1),1),
    VSTACK(HSTACK("Type of work:",work),
           HSTACK(supplier,
                  DROP(REDUCE("",TOCOL(C9:J9,1),
                       LAMBDA(g,x,
                              VSTACK(g,
                                     MAP(UNIQUE(TOROW(A11:A39,1),1),
                                  LAMBDA(y,
                                         LET(m,MATCH(x,C9:J9),
                                             p,FILTER(CHOOSECOLS(C11:J39,m+{1,0}),A11:A39=y),
                                             f,FILTER(p,TAKE(p,,1)<>""),
                                             t,TAKE(f,,1),
                                             n,DROP(f,,1),
                                             u,UNIQUE(t),
                                         IFERROR(TEXTJOIN("; ",,u&" "&ROUND(MAP(u,LAMBDA(v,SUM(n*(t=v))))/SUM(n)*100,)),
                                                 ""))))))),
                       1))))