+ Reply to Thread
Results 1 to 3 of 3

Normalize datasets

  1. #1
    Registered User
    Join Date
    01-27-2011
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    1

    Normalize datasets

    Hi.

    Excel 2010.

    We have a dataset of several thousand rows looking something like below:

    Method = ping
    Title = Jalla
    egenskap1 = hi
    egenskap2= bye
    egenskap3=banana

    Method = ping
    Title = something
    egenskap1 = hei
    egenskap2= hadet

    Method = ping
    Title = else
    egenskap1 = hei
    egenskap2= hadet
    egenskap3=banana
    egenskap4=mustard
    egenskap5=ketchup

    Short explanation: each group og rows describes an entity. We wan't to "normalize" these data, in other words, create a record/row for each entity. The union of all key-value-pairs will constitute the columns in the resulting sheet.

    The problem is that the number of key-value-pairs describing each entity varies. My first thought was to search for a key-value-manipulating function that also could detect the next intance of the entity: the criteria would be the next occurence of the string Method.

    Any pointers?

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Normalize datasets

    Use a macro, are there gaps between sets?

    Upload an example and I'll write something.
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,243

    Re: Normalize datasets

    This needs a little setting up so I have attached an example based on your data.

    It assumes that the data is in column A and only column A ... otherwise you are going to have to do some work of your own ;-) You will need a "helper" column in column B.

    The formula in cell B2 is: =IF(LEFT(A2,6)="Method",N(B1)+1,B1) ** and note that cell B1 must be blank **. You need to drag this formula down to the last row of your data.

    Then, if you want to leave the rest of row 1 blank, put the following formula in cell D2 and drag across and down:

    =IF(OR(ROW($A2)-1>MAX($B:$B),COLUMN(D$2)-COLUMN($D$2)>=COUNTIF($B:$B,ROW($A2)-1)),"",INDEX($A:$A,MATCH(ROW($A2)-1,$B:$B,0)+COLUMN(D$2)-COLUMN($D$2),1)&"")

    You need to drag down for as many rows as you have Method statements plus 1, that is, if you have 6 Method statements, you need the formula in rows 2 to 7.

    You also need to drag across as far as the maximum number of entities for a Method statement. I'm hoping you can work that out otherwise you'll need to guess.

    The further you have to drag across and down, the more formulae will be generated and the slower it will be ... so, keep it to the minimum you need to transpose the data.

    It is important to note that, if you put the formula in the top row, you will need to adjust it ... but see the example workbook.

    Once you have the data reflected in the rows, you need to copy it and then Paste Special | Values to rremove the formulae.

    You can use the following formula (in cell A1, or wherever) to count the number of Method statements:

    =SUMPRODUCT((LEFT(A2:A39,6)="Method")+0)

    Format as: 0 "x Method" to make it self explanatory.

    Lastly, as you're in Norway, I'm guessing you'll need to change all the commas in the formulae to semi-colons.

    There may be other and better ways to do this but, hopefully, it will give you something to be going on with.

    Regards
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1