transpose() function application

Sumanmathew

Board Regular
Joined
Jan 25, 2021
Messages
69
Office Version
  1. 2021
  2. 2013
Platform
  1. Windows
I need it as shown in TABLE 2, the items can vary from project to project. The transpose() array should expand and contract as items increase or decrease wihtout those zero rows being displayed.How to replace those 0 rows? Is it possible that way?
transposeTrial.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1MDBSDBCP
2qnty121qnty31qnty12141
3tot ac520ACC PR100150120tot ac520ACC PR100150tot ac520ACC PR100150120205
4tot pr6500U. PR100020001500tot pr5000U. PR10002000tot pr5000U.PR10002000150050050
57020ITEMSMDB-1MDB-2MDB-35520ITEMSSDB-1SDB-25520ITEMSCP-1CP-2CP-3CP-4CP-5
6
7
8
9
10SLITEMSQNTYU.PRACC.PRTOT. PR
11MDBTABLE 2
121MDB-1110001001100SLITEMSQNTYU.PRACC.PRTOT. PR
132MDB-2220001504300MDB
143MDB-31150012016201MDB-1110001001100
154000002MDB-2220001504300
165000003MDB-3115001201620
17SUBTOTAL4SUBTOTAL4
18SDBSDB
191SDB-13100010033001SDB-1310001003300
202SDB-21200015021502SDB-2120001502150
21300000SUBTOTAL4
22400000CP
235000001CP-1110001001100
24SUBTOTAL42CP-2220001504300
25CP3CP-3115001201620
261CP-11100010011004CP-44500202080
272CP-22200015043005CP-5150555
283CP-3115001201620SUBTOTAL4
294CP-44500202080GRAND TOTAL0
305CP-5150555
31SUBTOTAL4
32GRAND TOTAL0
33
Sheet1
Cell Formulas
RangeFormula
B3,T3,K3B3=SUMPRODUCT($D$3:$H$3,$D$2:$H$2)
B4B4=SUMPRODUCT($D$4:$H$4,$D$2:$H$2)
B5,T5,K5B5=SUM(B3:B4)
K4,T4K4=SUMPRODUCT($M$4:$Q$4,$M$2:$Q$2)
D12:D16D12=TRANSPOSE(D5:H5)
E12:E16E12=TRANSPOSE(D2:H2)
F12:F16F12=TRANSPOSE(D4:H4)
G12:G16G12=TRANSPOSE(D3:H3)
H12:H16,H26:H30,H19:H23H12=(F12+G12)*E12
E17,E31E17=SUM(E12:E14)
D19:D23D19=TRANSPOSE(M5:Q5)
E19:E23E19=TRANSPOSE(M2:Q2)
F19:F23F19=TRANSPOSE(M4:Q4)
G19:G23G19=TRANSPOSE(M3:Q3)
E24E24=SUM(E19:E23)
D26:D30D26=TRANSPOSE(V5:Z5)
E26:E30E26=TRANSPOSE(V2:Z2)
F26:F30F26=TRANSPOSE(V4:Z4)
G26:G30G26=TRANSPOSE(V3:Z3)
H32H32=SUM(H17+H24+H31)
Press CTRL+SHIFT+ENTER to enter array formulas.
Dynamic array formulas.
 
This may be more effort than it's worth, but the following should return the entire output table in a single dynamic array, using functions that are compatible with Excel 2021:
Excel Formula:
=LET(
    lbl, TRANSPOSE(FILTER(A1:Z1, A1:Z1 <> "")),
    pId, QUOTIENT(COLUMN(A1:Z1) - 4, 9),
    rId, IF(LEN(A1:Z1), A1:Z1, MOD(COLUMN(A1:Z1) - 4, 9) + 1),
    qty, A2:Z2,
    apr, A3:Z3,
    upr, A4:Z4,
    itm, A5:Z5,
    tot, qty * (upr + apr),
    tbl, TRANSPOSE(CHOOSE(SEQUENCE(7), pId, rId, itm, qty, upr, apr, tot)),
    bdy, FILTER(tbl, (INDEX(tbl, 0, 2) < 6) * (INDEX(tbl, 0, 3) <> 0)),
    key, SEQUENCE(ROWS(lbl), 1, 0),
    cId, MOD(SEQUENCE(1, 7, -2), 7),
    hdr, IF(cId = 5, key, IF(cId, "", lbl)),
    val, IFERROR(--bdy, 0),
    sub, IF(cId = 5, key, IF(cId = 6, "", IF(cId, MMULT(--(TRANSPOSE(INDEX(bdy, 0, 1)) = key), val), "SUBTOTAL"))),
    grd, IF(cId = 5, MAX(key) + 1, IF(cId = 6, "", IF(cId, MMULT(SEQUENCE(1, ROWS(bdy), 1, 0), val), "GRAND TOTAL"))),
    _h1, ROWS(hdr),
    _h2, ROWS(bdy),
    _r1, SEQUENCE(_h1 * 2 + _h2 + 1, 1, 1 - _h1),
    _r2, _r1 - _h2,
    col, SEQUENCE(1, COLUMNS(bdy)),
    arr, SORT(IF(_r1 < 1, hdr, IF(_r1 <= _h2, INDEX(bdy, _r1, col), IF(_r2 <= _h1, INDEX(sub, _r2, col), grd)))),
    INDEX(arr, SEQUENCE(ROWS(arr)), SEQUENCE(1, COLUMNS(arr) - 1, 2))
)
Please note, this solution is based on each project being allocated the same number of available columns in the worksheet (which is 9 in your mini-sheet example). Cheers!
 
Upvote 0
Improved/updated to accommodate a variable number of columns for each project:
Excel Formula:
=LET(
    col, COLUMN(A1:AZ1),
    key, TRANSPOSE(FILTER(col, LEN(A1:AZ1))),
    lbl, INDEX(1:1, key),
    cId, VLOOKUP(col, key, 1, 1),
    rId, col - IFNA(VLOOKUP(cId, key, 1, 0), 0),
    qty, A2:AZ2,
    apr, A3:AZ3,
    upr, A4:AZ4,
    itm, A5:AZ5,
    num, 7,
    tbl, TRANSPOSE(CHOOSE(SEQUENCE(num), cId, rId, itm, qty, upr, apr, qty * (upr + apr))),
    bdy, FILTER(tbl, INDEX(tbl, 0, 2) * ISTEXT(INDEX(tbl, 0, 3))),
    _h1, ROWS(key),
    _h2, ROWS(bdy),
    _r1, SEQUENCE(_h1 * 2 + _h2 + 1, 1, 1 - _h1),
    _r2, _r1 - _h2,
    _c1, SEQUENCE(1, num),
    _c2, MOD(_c1 - 3, num),
    _t1, _c2 = 5,
    _t2, _c2 = 6,
    hdr, IF(_t1, key, IF(_c2, "", lbl)),
    val, IFERROR(--bdy, 0),
    sub, IF(_t1, key, IF(_t2, "", IF(_c2, MMULT(--(TRANSPOSE(INDEX(bdy, 0, 1)) = key), val), "SUBTOTAL"))),
    grd, IF(_t1, MAX(key), IF(_t2, "", IF(_c2, MMULT(SEQUENCE(1, _h2, 1, 0), val), "GRAND TOTAL"))),
    arr, SORT(IF(_r1 < 1, hdr, IF(_r1 <= _h2, INDEX(bdy, _r1, _c1), IF(_r2 <= _h1, INDEX(sub, _r2, _c1), grd)))),
    INDEX(arr, SEQUENCE(ROWS(arr)), SEQUENCE(1, num - 1, 2))
)
Adjust the range references as needed.
 
Upvote 0

Forum statistics

Threads
1,226,797
Messages
6,193,051
Members
453,772
Latest member
aastupin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top