0

I have an Excel with rows and columns as below:

enter image description here

I need to build a series like below in Excel with two columns as shown:

enter image description here

I have a huge data set where rows are dates and columns are data in half hours.

Which would be the best method?

pnuts
  • 58,317
  • 11
  • 87
  • 139
CoolDiva
  • 209
  • 1
  • 3
  • 14
  • I am afraid I don't quite understand your problem? What happens to `data` in your Combination Series? What are the rules for including a,b,c and 1,2,3 in the Series? – martin Oct 06 '15 at 21:43
  • I can do a vlookup to fetch data once I get the series combination.There are no rules of including the data. It is just data I have to upload data in this format – CoolDiva Oct 06 '15 at 21:45
  • I have added another example with screenshot in my question – CoolDiva Oct 06 '15 at 21:51
  • So basically, you have _n_ rows and _m_ columns and your goal is to have a list with length _m_ * _n_, with all combinations of row headings and column headings? – martin Oct 06 '15 at 21:51
  • exactly I would like to have a list with all rows and column combinations – CoolDiva Oct 06 '15 at 21:53
  • While this can likely be performed with array formulas and volatile functions, it seems an inefficient method of generating a 'flattened' list of the combinations from row 1 and column A. Would a VBA-based solution fit better? –  Oct 06 '15 at 22:06
  • Not sure you'll be able to do very easily that with just formulas, but some searching shows there's tools out there do this kind of stuff - e.g. http://www.extendoffice.com/documents/excel/705-excel-convert-table-to-list.html – zzevannn Oct 06 '15 at 22:07
  • Possible duplicate of [How to "flatten" or "collapse" a 2D Excel table into 1D?](http://stackoverflow.com/questions/687470/how-to-flatten-or-collapse-a-2d-excel-table-into-1d) – zzevannn Oct 06 '15 at 22:12
  • Probably you don't need the data combinations if you have the coordinates, then you can use the coordinates to INDEX instead of VLOOKUP, see my response before you posted the sample data. – EEM Oct 06 '15 at 22:57
  • @zzevannn - That one is pretty close but the request was for a VBA solution and solved with a combination of VBA and Pivot Tables. This was specified as a worksheet formula problem. –  Oct 06 '15 at 23:13

4 Answers4

0

I would suggest using the INDIRECT function thus:

In the column when you want to have the Row labels, put this formula:

=INDIRECT("R" & MOD(ROW()-1, COUNTA(A:A))+2 & "C1",FALSE)

Here A:A refers to the column where your row labels are stored and +2 is offset to the first row with a label.

In the column where you want the Column labels, put:

=INDIRECT("R1C" & ROUNDDOWN((ROW()-1)/COUNTA($B$1:$D$1),0)+2,FALSE)

Here $B$1:$D$1 refers to the range with your column labels, and +2 is again offset to the first column label.

martin
  • 2,520
  • 22
  • 29
0

Assuming your data is in the range C7:F12

enter image description here

We’ll need three fields to show the resulting series: Row, Col and Data

Row: in cell H7 enter this formula and copy till the last record:

=IF(EXACT(H6,H$6),1,
IF(EXACT($I7,CHAR(133)),"",
IF($I7=1,SUM(1,H6),H6)))

Col: in cell I7 enter this formula and copy till the last record:

=IF(EXACT(I6,I$6),1,
IF(EXACT(I6,CHAR(133)),CHAR(133),
IF(I6=COLUMNS($C$7:$F$12),
IF(H6=ROWS($C$7:$F$12),CHAR(133),1),
SUM(1,I6))))

Data: in cell J7 enter this formula and copy till the last record:

=IF(EXACT($I7,CHAR(133)),"",
INDEX($C$7:$F$12,$H7,$I7))

enter image description here

EEM
  • 6,601
  • 2
  • 18
  • 33
0

Posting a revised answer following sample data provided by user (left prior answer as it might be useful to other users)

Assuming your data is in the range C6:K11

We’ll need four fields to show the resulting series: Row, Col, 'DateandTime`

Row: in cell M7 enter this formula and copy till the last record:

=IF(EXACT(M6,M$6),1,
IF(EXACT($N7,CHAR(133)),"",
IF($N7=1,SUM(1,M6),M6)))

Col: in cell N7 enter this formula and copy till the last record:

=IF(EXACT(N6,N$6),1,
IF(EXACT(N6,CHAR(133)),CHAR(133),
IF(N6=COLUMNS($C$6:$K$6),
IF(M6=ROWS($B$7:$B$11),CHAR(133),1),
SUM(1,N6))))

Date: in cell O7 enter this formula and copy till the last record:

=IF(EXACT($N7,CHAR(133)),"",
INDEX($B$7:$B$11,$M7,0))

Time: in cell P7 enter this formula and copy till the last record:

=IF(EXACT($N7,CHAR(133)),"",
INDEX($C$6:$K$6,0,$N7))

enter image description here

Fields Row and Col can be hidden

EEM
  • 6,601
  • 2
  • 18
  • 33
0

The following will produce your results but the array formula will impact calculation lag depending upon the number of rows and column of data in the original data matrix.

    Flatten rows and columns

The array formula¹ in A10 is,

=IFERROR(INDEX(A$2:A$6, MATCH(0, IF(COUNTIF(A$9:A9, A$2:A$6&"")<COUNT($1:$1), 0, 1), 0)), "")

The standard formula in B10 is,

=IF(LEN(A10), INDEX($B$1:INDEX($1:$1, MATCH(1E+99,$1:$1 )), , COUNTIF(A$10:A10, A10)), "")

Data retrieval in C10 is accomplished with,

=INDEX(A:J,MATCH(A10,A:A,0),MATCH(B10,$1:$1,0))

Fill down as necessary.


¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.

  • btw, the times across row 1 are real times and are treated as numbers. If they were text that looked like times (i.e. *numbers*) then the [COUNTA function](https://support.office.com/en-us/article/counta-function-47239e46-e523-40f4-94d7-fa2e1711fd4a) would be a better choice than the [COUNT function](https://support.office.com/en-au/article/COUNT-function-a59cd7fc-b623-4d93-87a4-d23bf411294c). –  Oct 06 '15 at 23:07