-1

I have the following incoming data:

Date Data ID
03/21 Red: 10 01
03/21 Blue: 5 02
04/21 Red: 20, Blue: 15 03
04/21 Green: 7 04
04/21 Red: 13, Green: 15 05

I have managed to separate the data into its components as shown below:

Date Data ID Color 1 Value 1 Color 2 Value 2
03/21 Red: 10 01 Red 10
03/21 Blue: 5 02 Blue 5
04/21 Red: 20, Blue: 15 03 Red 20 Blue 15
04/21 Green: 7 04 Green 7
04/21 Red: 13, Green: 15 05 Red 13 Green 15

I want to create a function that looks at each month and sums the values for each color. An example is below:

Date Red Blue Green
03/21 10 5 0
04/21 13 0 22

I have absolutely no control over the incoming data. Any help would be greatly appreciated.

1 Answers1

0

With Excel O365 you can directly achieve your desired output without any helper table. Use nested FILTERXML() formula with Textjoin(). As per my below screenshot use below formula to F2 cell.

=SUM(IFERROR(FILTERXML("<t><s>"&SUBSTITUTE(FILTERXML("<t><s>"&SUBSTITUTE(TEXTJOIN(", ",TRUE,IF($A$2:$A$6=$E2,$B$2:$B$6,"")),", ","</s><s>")&"</s></t>","//s[contains(., '"&F$1&"')]"),": ","</s><s>")&"</s></t>","//s[last()]"),0))

For date column to extract unique dates/month you can use UNIQUE() function to E2 cell,

=UNIQUE(A2:A6)

enter image description here

Here is detailed explanation of FILTERXML() function from @JvdV.

Harun24hr
  • 30,391
  • 4
  • 21
  • 36