Dynamic table? maybe?

ExcelQA

New Member
Joined
Sep 21, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi everyone, I have little bit of a challenge. I developed a model for a colleague who is very used to "his format". Is there a way to create a dynamic (non pivot table) to automatically transform the data into one with the format below? the challenge is that for example on the table below the level 0 and level 2 changes month over month


1696592791209.png
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe something like this would work...you pick Level 0 from the dropdown in H1 and see the results. The potential problem with stacking results as shown is that if there are more or fewer rows under any Level 0, other results should shift up or down. I also noticed that SWE and US do not have totals.
Book_2023-10-03.xlsm
ABCDEFGHIJ
1Level 2Level 1Level 0TotalRUUS
2Mig29ABCRU1,000UKBaloon100
3SU35ABCRU1,700SWEF223,000
4TornadoDCBUK2,000USV22800
5TyphoonDCBUK2,500F161,000
6ViggenXCYSWE1,000Total:4,900
7GrippenXCYSWE1,700
8BaloonDEFUS100
9F22DEFUS3,000
10V22DEFUS800
11F16DEFUS1,000
Sheet7
Cell Formulas
RangeFormula
F1:F4F1=UNIQUE(C2:C11)
I2:J6I2=LET(filt,FILTER(CHOOSE({1,2},A2:A11,D2:D11),C2:C11=H1),b,HSTACK("Total:",SUM(INDEX(filt,,2))),VSTACK(filt,b))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
H1List=$F$1#

Hope that helps,

Doug
 
Upvote 0
Maybe the below code will give you the layout you need, i have assumed that the range you supplied was A1:D11:
VBA Code:
Sub test()
    Dim rng As Range, var As Variant
    Dim uLevel0 As Variant, x As Long, z As Long, a As Long
    Dim oVar As Variant
    Dim oRng As Range, rCell As Range
    
    Set rng = Range("A2:D" & Range("A" & Rows.Count).End(xlUp).Row)
    var = rng.Value
    
    With Application
        uLevel0 = .Unique(.Index(rng, , 3))
        ReDim oVar(.CountA(.Index(rng, , 3)) + UBound(uLevel0) * 2, 2)
        For x = 1 To UBound(uLevel0)
            oVar(z, 0) = uLevel0(x, 1): z = z + 1
            For a = 1 To UBound(var)
                If var(a, 3) = uLevel0(x, 1) Then
                    oVar(z, 1) = var(a, 1)
                    oVar(z, 2) = Format(var(a, 4), "0,0")
                    z = z + 1
                End If
            Next a
            oVar(z, 2) = Format(.SumIf(.Index(rng, , 3), uLevel0(x, 1), .Index(rng, , 4)), "0,0")
            z = z + 1
        Next x
        Set oRng = Range("G2").Resize(UBound(oVar) + 1, 3)
        oRng = oVar
        For Each rCell In .Index(oRng, , 1)
            If rCell.Value <> vbNullString Then
                With rCell.Font
                    .Color = 10384908
                    .Bold = True
                End With
            ElseIf rCell.Offset(, 2) <> vbNullString And rCell.Offset(, 1) = vbNullString Then
                With rCell.Offset(, 2).Font
                    .Bold = True
                End With
            End If
        Next rCell
    End With
End Sub
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGH
1Level 2Level 1Level 0Total
2Mig29ABCRU1000RU
3SU35ABCRU1700Mig291000
4TornadoDCBUK2000SU351700
5TyphoonDCBUK25002700
6ViggenXCYSWE1000UK
7GrippenXCYSWE1700Tornado2000
8BaloonDEFUS100Typhoon2500
9F22DEFUS30004500
10V22DEFUS800SWE
11F16DEFUS1000Viggen1000
12Grippen1700
132700
14US
15Baloon100
16F223000
17V22800
18F161000
194900
20
Sheet3
Cell Formulas
RangeFormula
F2:H19F2=LET(u,UNIQUE(FILTER(C2:C100,C2:C100<>"")),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,VSTACK(EXPAND(y,,3,""),IFNA(HSTACK("",FILTER(CHOOSECOLS(A2:D100,1,4),C2:C100=y)),"")),CHOOSE({1,2,3},"","",SUMIFS(D:D,C:C,y))))),1))
Dynamic array formulas.
 
Upvote 0
Realised I had an extra vstack which is not need, so updated formula
Excel Formula:
=LET(u,UNIQUE(FILTER(C2:C100,C2:C100<>"")),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,EXPAND(y,,3,""),IFNA(HSTACK("",FILTER(CHOOSECOLS(A2:D100,1,4),C2:C100=y)),""),CHOOSE({1,2,3},"","",SUMIFS(D:D,C:C,y))))),1))
 
Upvote 0
Realised I had an extra vstack which is not need, so updated formula
Excel Formula:
=LET(u,UNIQUE(FILTER(C2:C100,C2:C100<>"")),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,EXPAND(y,,3,""),IFNA(HSTACK("",FILTER(CHOOSECOLS(A2:D100,1,4),C2:C100=y)),""),CHOOSE({1,2,3},"","",SUMIFS(D:D,C:C,y))))),1))
I love this solution! thank you i think this does the trick...
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Thank you and sorry for the newbie question... I've never user Stacks.. what if I want to add more columns, somehow i cant get the totals to work

1696628337951.png
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHIJKLM
1Level 2Level 1Level 0Total
2Mig29ABCRU1000397889RU
3SU35ABCRU1700617224Mig291000397889
4TornadoDCBUK2000909784SU351700617224
5TyphoonDCBUK2500892852270010141113
6ViggenXCYSWE1000367497UK
7GrippenXCYSWE1700598866Tornado2000909784
8BaloonDEFUS100314317Typhoon2500892852
9F22DEFUS3000937501450018011636
10V22DEFUS800442502SWE
11F16DEFUS1000390885Viggen1000367497
12Grippen1700598866
1327009651363
14US
15Baloon100314317
16F223000937501
17V22800442502
18F161000390885
19490020832205
Sheet3
Cell Formulas
RangeFormula
I2:M19I2=LET(u,UNIQUE(FILTER(C2:C100,C2:C100<>"")),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,VSTACK(EXPAND(y,,5,""),IFNA(HSTACK("",FILTER(CHOOSECOLS(A2:F100,1,4,5,6),C2:C100=y)),"")),CHOOSE({1,2,3,4,5},"","",SUMIFS(D:D,C:C,y),SUMIFS(E:E,C:C,y),SUMIFS(F:F,C:C,y))))),1))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,215,205
Messages
6,123,632
Members
449,109
Latest member
Sebas8956

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