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:

AB
1Type CodeAmount
2110
3220
4330
5440
6550

<tbody>
</tbody>

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

ABC
10Type DescType CodeAmt
11A110
12B220
13C1,230
14D550
15E440

<tbody>
</tbody>
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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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