Solved

Denormalize Excel Data

Posted on 2012-12-30
12
2,738 Views
Last Modified: 2013-01-23
I don't know that "denormalize" is technically the correct term, so to you database guys, I apologize up front, but it's the best I could come up with to describe my need.

I am being given the output of a relational database in Excel format, where there is a one-to-many relationship between "person name" and "position code". For each person, one row is output for each position held. The "key" is the name, which is the "one" side of the relationship.

I'm not bad with Excel, but this is beyond my pay grade: I want to have, for each name, a cell that has the concatenated set of positions to which that person is assigned. An example:

Input
Name   | Position
John   | AA
John   | BB
Tom    | AA
Harry  | BB
Harry  | CC
Harry  | DD

Open in new window

Desired Output:
Name   | Positions
John   | AA, BB
Tom    | AA
Harry  | BB, CC, DD

Open in new window

If at all humanly possible, I do NOT want to use VBA, and stay fully within the Excel environment to solve the problem.
0
Comment
Question by:propertytax
  • 4
  • 4
  • 3
12 Comments
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 38731436
Hello,

Excel does not provide that functionality out of the box. You would need a custom formula written with VBA.

The closest you can get with out of the box functionality is to build a pivot table as the attached.

cheers, teylyn
Pivot.xlsx
0
 

Author Comment

by:propertytax
ID: 38731444
Yeah, I ran down the Pivot Table rabbit hole myself; I've seen some very fancy things done with VLOOKUP and am hoping someone clever can put something together, but if VBA is the only solution I'm going to have to go another route :-(

Thanks for the suggestion, though.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38731458
Hi, propertytax.

A few questions, please...
(1) In your source example, all of the entries for an individual are grouped together. Is this true for the actual data?
(2) May we add a helper column (or two!) beside the source data?
(3) May we assume a maximum no. of entries?
(4) How does the source data get from the database to the spreadsheet which will contain the results?

Thanks,
Brian.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:propertytax
ID: 38731473
1) The entries for each name are grouped by name; further, they are sorted by name ascending, which is the primary (and only) sort key

2) Yes, we're free to add any helper columns we would care to, the data is "branched" from the database and we can manipulate at will

3) We may assume a maximum of 4 positions per name

4) The data is delivered to me as an Excel spreadsheet; I have no direct access to the database itself.

I've been playing with ARRAY formulas but I am just so terrible at those, I haven't a clue where to start.
0
 
LVL 50

Assisted Solution

by:Ingeborg Hawighorst
Ingeborg Hawighorst earned 125 total points
ID: 38731490
Hello,

please see attached a suggestion with helper columns that can be hidden.

Column E has the formula

=IF(ISERROR(MATCH($D2&E$1,INDEX($A$1:$A$20&$B$1:$B$20,0),0)),0,E$1)

Column F has
=IF(COUNTA($E2:E2)>0,E2&", ","")&IF(ISERROR(MATCH($D2&F$1,INDEX($A$1:$A$20&$B$1:$B$20,0),0)),0,F$1)

Hide columns E to H. In column I use

=SUBSTITUTE(SUBSTITUTE(H2,", 0",""),"0, ","")

This can be expanded to as many positions as there are in the data.

You can use a pivot table to set up the initial grid of unique names in the rows and unique list of positions in the column headers. Then copy the unique names and use paste special > values to paste to a new table. Copy the unique position names and paste special > values across the top.

cheers, teylyn
NotPivot.xlsx
0
 
LVL 26

Accepted Solution

by:
redmondb earned 375 total points
ID: 38731591
Thanks, propertytax.

Please see the attached. A few points...
(1) The formulas are in the yellow (and one red) cells. Copy them down for as many as rows as you have data in column A. You can overshoot (as I have in rows 28 to 31) without breaking anything.
(2) If you want to be fancy the formulas in columns F anf H:I only need to go down as many rows as the number of unique names (E2).
(3) The red cell is highlighted because, apologies, its formula is different from the other cells in that column.
(4) If you may have more than 5,000 entries in column A then the formulas in column F need to be changed.

Regards,
Brian.
Denormalize-No-VBA.xlsx
0
 

Author Comment

by:propertytax
ID: 38753453
Sorry, both - came down with something or other, keeping me on my back for now. I'll get back to this shortly, though. I appreciate the responses.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38753476
Thanks for the update, propertytax. All the best for a speedy recovery,
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 38790259
Hello, thanks for closing the question, but can you please explain the B grade? If you don't assign an A grade, you should explain what aspect of the answers you are not happy with, so experts can improve their suggestions.

If you are not happy with the way that Excel works, then that does not mean the question gets a B, though. Experts are not responsible for the way Excel works.
0
 

Author Comment

by:propertytax
ID: 38808534
I've requested that the moderators change the grade on this question.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38809422
Thanks, all.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question