Dynamic Array Constant

bkjohn2016

New Member
Joined
Sep 9, 2016
Messages
38
Is it possible to reference another cell to use as an array constant?

Let's say in table A I have the following data:

[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Type Code[/TD]
[TD]Amount[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]3[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]4[/TD]
[TD]40[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]5[/TD]
[TD]50[/TD]
[/TR]
</tbody>[/TABLE]

And I'd like the the amount aggregated by the type code in table B:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]Type Desc[/TD]
[TD]Type Code[/TD]
[TD]Amt[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]A[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]B[/TD]
[TD]2[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]C[/TD]
[TD]1,2[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]D[/TD]
[TD]5[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]E[/TD]
[TD]4[/TD]
[TD]40[/TD]
[/TR]
</tbody>[/TABLE]
I use the following formulation to get the aggregations in column C of table B:

Code:
=SUMPRODUCT(--(A$1:$A$6=$B11),
$B$2:$B$6)

And for C13 I can use the following to get the desired result of 30:
Code:
=SUMPRODUCT(--($A1:$A$6={1,2})*
$B$1:$B$6)

Is it possible to create a formulation that would use cell B13 to create a dynamic array constant?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I have 2 solutions. First, a Power Query solution, which I think is more dynamic and better in general.

Add Table1, add Table2, then here are the Table2 transformations:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(Source, {{"Type Code", type text}}, "en-US"), "Type Code", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Type Code.1", "Type Code.2", "Type Code.3"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Type Code.1", Int64.Type}, {"Type Code.2", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Type Desc"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Value", Int64.Type}})
in
    #"Changed Type1"

Merge Table1 and Table2 as new query, then transformations:
Code:
let
    Source = Table.NestedJoin(Table1,{"Type Code"},Table2,{"Value"},"Table2",JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Type Desc", "Value"}, {"Type Desc", "Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Type Code", "Value"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Type Desc", "Amount"}),
    #"Replaced Value" = Table.ReplaceValue(#"Reordered Columns",null,"",Replacer.ReplaceValue,{"Type Desc"}),
    #"Filtered Rows" = Table.SelectRows(#"Replaced Value", each [Type Desc] <> null and [Type Desc] <> ""),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Type Desc"}, {{"Total", each List.Sum([Amount]), type number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Type Desc", Order.Ascending}})
in
    #"Sorted Rows"

And here is the formula solution. It is an array formula so Ctrl+Shift+Enter when entering the formula:

Code:
=SUM(IFERROR(LOOKUP(MID(SUBSTITUTE(B13,",",0),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(B13,",",0)))),1)+0,$A$2:$A$6,$B$2:$B$6),0))
 
Upvote 0
Here's another method. This one involves defining a name, and then using it in the formula. Since the reference for the defined name is a relative reference, you'll need to first select cell C11. Then, with the cell selected, define the following name (Ribbon >> Formulas >> Defined Names >> Define Name)...

Code:
Name:  MyArray

Refers to:  =EVALUATE("{"&'Sheet1'!$B11&"}")

Click OK

Then try...

Code:
C11, copied down:

=SUMPRODUCT(SUMIF($A$2:$A$6,MyArray,$B$2:$B$6))

Note, though, you'll need to ensure that the values in Column B in Table B do not start or end with a comma.

Hope this helps!
 
Last edited:
Upvote 0
Ha! Evaluate in a named range...that's perfect! I did not know that EVALUATE could be used outisde VBA. Irobbos suggestion was also considered but I failed to mention that my client has acute excel anxiety and is intimidated by advanced techniques. Looks like I've learned something new...thank you both so much!
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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