Incorporate SUM by cell color in a formula with HSTACK, MAP, TEXTJOIN and LAMBDA.

Lixxy

New Member
Joined
Sep 20, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have two tables, A and B. Table A is countries planned and Table B is planed driven KM.
I also have a summary where I want to see total planed KM, per country, and what calendar weeks that specific country is planed.

I have a formula that summarizes planed driven km in a set of specific countries (B3).
I have a second formula that uses TEXTJOIN to list the calendar weeks each country is planned (C3).

So far so good. But now comes my issue...
Table A and Table B contains plans for two different purposes, differentiated by different colored cells (manually applied) in both tables. Currently both formulas does a sum total, regardless of color.
For the summary to be useful, it needs to be able to summarize one color at a time, preferably by a referenced cell.

If we take DK for example, and the result I would like to get:
DK: 500 KM (CW14) -- Blue cells
DK: 200 KM (CW12; CW13) -- Green cells

I have tried to look into VBA and a function to sum by color, but how ever I do it I cannot get it to work with the rest of the formula.

Can this be done? with VBA?
Or are they any other smart solutions to this problem?


SampleKMCW.xlsm
ABCDEFGHIJ
1SummaryTable ACW12CW13CW14CW15
2CountriesKMCWCar 1transportDKDK-DEDE
3SE650CW12; CW15
4DK700CW12; CW13; CW14Car2SEFIEELV
5FI300CW13
6DE500CW12; CW13; CW14; CW15Car3SE-DK-DEDEDKSE
7LV150CW15
8EE250CW14Table BCW12CW13CW14CW15
9Car 1transport150200150
10
11Car2150300250150
12VAL
13DEVCar3150200400450
Sheet1
Cell Formulas
RangeFormula
B3:B8B3=HSTACK(MAP(UNIQUE(TOCOL(TEXTSPLIT(A3:A8,"-"))),LAMBDA(z,SUMPRODUCT(N(ISNUMBER($G$9:$J$13)),$G$9:$J$13,N(ISNUMBER(FIND(z,$G$2:$J$6)))/MAP($G$2:$J$6,LAMBDA(x,COUNTA(TEXTSPLIT(x,"-"))))))))
C3:C8C3=IFERROR(MAP(A3:A8,LAMBDA(x,TEXTJOIN("; ",,UNIQUE(TOCOL(IFS(FIND(x,$G$2:$J$6),$G$1:$J$1),3,1))))),"")
Dynamic array formulas.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How about this then,

I create a third table (C), which is populated with GET.CELL to get the cell color from Table A.
I have another GET.CELL next to the color reference (VAL).

Is it now possible to incorporate into the existing formula that only the cells "37" from Table C is to be used?

The named ranges with Get.Cell i've defined are:
SumColor (N2) --> =GET.CELL(38;Sheet1!G2)
SumColorRef (C12) --> =GET.CELL(38;!B12)

SampleKMCW.xlsm
ABCDEFGHIJKLMNOPQ
1SummaryTable ACW12CW13CW14CW15Table CCW12CW13CW14CW15
2CountriesKMCWCar 1transportDKDK-DEDECar 10363737
3SE650CW12; CW15
4DK700CW12; CW13; CW14Car2SEFIEELVCar237373737
5FI300CW13
6DE500CW12; CW13; CW14; CW15Car3SE-DK-DEDEDKSECar336373737
7LV150CW15
8EE250CW14Table BCW12CW13CW14CW15
9Car 1transport150200150
10
11Car2150300250150
12VAL37
13DEV36Car3150200400450
Sheet1
Cell Formulas
RangeFormula
N2:Q2,N6:Q6,N4:Q4N2=SumColor
B3:B8B3=HSTACK(MAP(UNIQUE(TOCOL(TEXTSPLIT(A3:A8,"-"))),LAMBDA(z,SUMPRODUCT(N(ISNUMBER(Milestones)),Milestones,N(ISNUMBER(FIND(z,DraftPlan)))/MAP(DraftPlan,LAMBDA(x,COUNTA(TEXTSPLIT(x,"-"))))))))
C3:C8C3=IFERROR(MAP(A3:A8,LAMBDA(x,TEXTJOIN("; ",,UNIQUE(TOCOL(IFS(FIND(x,DraftPlan),DraftPlanCW),3,1))))),"")
C12:C13C12=SumColorRef
Dynamic array formulas.
Named Ranges
NameRefers ToCells
DraftPlan=Sheet1!$G$2:$J$6B3:C3, N2
DraftPlanCW=Sheet1!$G$1:$J$1C3
Milestones=Sheet1!$G$9:$J$13B3
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Incorporate SUM by cell color in a formula with HSTACK, MAP and LAMBDA. [SOLVED]
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
My apologies,

This is a cross-post and those can be found here, and the solution presented in both:

This issue has been Solved.

Thank you
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

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