0

I have data that is a function of two parameters that is imported from a .yaml file. The first column contains one of the parameters, the second column contains the data grouped by the second parameter which is included at the beginning of each group. I want to transform this data into a 2-dimensional table in Excel for graphing multiple parameterized lines.

The .yaml file looks like this. It will always be fixed length:

A:
  a: 1
  b: 2
  c: 3
B:
  a: 4
  b: 5
  c: 6

The imported data looks like this in Power Query (after importing as non-delimited text and minor manipulation in Excel Power Query):

Column1  |  Column2
-------------------
  null   |    A
   a     |    1
   b     |    2
   c     |    3
  null   |    B
   a     |    4
   b     |    5
   c     |    6

I'd like to transform it to this:

Column1 | Column2 | Column3
---------------------------
 null   |    A    |   B
  a     |    1    |   4
  b     |    2    |   5
  c     |    3    |   6

I don't need a complete solution, just a yes or no for whether it can be done, and the key concepts of the solution if it can be done. I'll fill in the details for any solutions as I have time to work through them (since this is what Stack Exchange wants to see, detailed solutions).

4
  • If it's fixed size like in your sample, you can make QueryA and QueryB with some mix of Table.FirstN, Table.LastN, Table.Range, and Table.Skip. Then you can merge (UI label for joining) with Table.Join, based on a join column of your [Column1]. Commented Sep 24, 2019 at 21:45
  • Thanks! I figured out another way that I will add here, but will try your solution too. Commented Sep 24, 2019 at 23:47
  • Group the rows by Column1. Use Table.Column to convert to a List. Expand the list with a delimiter separation. Split the expanded list to the new columns. Delete the unneeded columns. Commented Sep 25, 2019 at 1:40
  • Thanks. I'll look at this approach too. Commented Sep 25, 2019 at 2:12

2 Answers 2

0

It seems like this approach should work, but I don't know how to do the third step.

Column1  |  Column2
-------------------
  null   |    A
   a     |    2
   b     |    1
   c     |    6
  null   |    B
   a     |    5
   b     |    4
   c     |    3

Add conditional Column3 based off of Column1

Column1  |  Column2  |  Column3
-------------------------------
  null   |    A      |    0
   a     |    2      |   null
   b     |    1      |   null
   c     |    6      |   null
  null   |    B      |    0
   a     |    5      |   null
   b     |    4      |   null
   c     |    3      |   null

Here is the step I do not know how to do! In this simple example, there is only one change.

Column1  |  Column2  |  Column3
-------------------------------
  null   |    A      |    0
   a     |    2      |   null
   b     |    1      |   null
   c     |    6      |   null
  null   |    B      |    1
   a     |    5      |   null
   b     |    4      |   null
   c     |    3      |   null

Fill Column3 down

Column1  |  Column2  |  Column3
-------------------------------
  null   |    A      |    0
   a     |    2      |    0
   b     |    1      |    0
   c     |    6      |    0
  null   |    B      |    1
   a     |    5      |    1
   b     |    4      |    1
   c     |    3      |    1

Pivot

Column1  |    0      |    1
-------------------------------
  null   |    A      |   null
  null   |   null    |    B
   a     |    2      |   null
   a     |   null    |    5
   b     |    1      |   null
   b     |   null    |    4
   c     |    6      |   null
   c     |   null    |    3

Fill Upward on (Column) 1, Filter null on (Column) 0

Column1  |    0      |    1
-------------------------------
  null   |    A      |    B
   a     |    2      |    5
   b     |    1      |    4
   c     |    6      |    3
Sign up to request clarification or add additional context in comments.

Comments

0

Here is the way I solved this after a search. Note that this is not ideal because it only works for a fixed size file. This could be parameterized, but there is likely a way to make it work for a variable sized file without needing the sizes entered as parameters. Also, I scrambled the data a bit to more closely resemble the actual problem.

This is a simplified rendition of my .yaml file. I read this in as text without delimiters.

 A:
   a: 2
   b: 1
   c: 6
 B:
   a: 5
   b: 4
   c: 3

By using the Find & Replace (I used four steps)

,A
a,2
b,1
c,6
,B
a,5
b,4
c,3

Split Column by Delimiter (a comma here)

Column1  |  Column2
-------------------
  null   |    A
   a     |    2
   b     |    1
   c     |    6
  null   |    B
   a     |    5
   b     |    4
   c     |    3

Added Index and Inserted Modulo 4 column(operates on Column3 to create Column4)

Column1  |  Column2  |  Column3  |  Column4
-------------------------------------------
  null   |    A      |     0     |    0
   a     |    2      |     1     |    1
   b     |    1      |     2     |    2
   c     |    6      |     3     |    3
  null   |    B      |     4     |    0
   a     |    5      |     5     |    1
   b     |    4      |     6     |    2
   c     |    3      |     7     |    3

Sorted Rows by Column4, added another index, and added a modulo 2 column.

Column1  |  Column2  |  Column3  |  Column4  |  Column5  |  Column6
-------------------------------------------------------------------
  null   |    A      |     0     |     0     |     0     |    0
  null   |    B      |     4     |     0     |     1     |    1
   a     |    2      |     1     |     1     |     2     |    0
   a     |    5      |     5     |     1     |     3     |    1
   b     |    1      |     2     |     2     |     4     |    0
   b     |    4      |     6     |     2     |     5     |    1
   c     |    6      |     3     |     3     |     6     |    0
   c     |    3      |     7     |     3     |     7     |    1

Sort on Column6 to get groupings of rows that will go into a single column, with the column number in Column6

Column1  |  Column2  |  Column3  |  Column4  |  Column5  |  Column6
-------------------------------------------------------------------
  null   |    A      |     0     |     0     |     0     |    0
   a     |    2      |     1     |     1     |     2     |    0
   b     |    1      |     2     |     2     |     4     |    0
   c     |    6      |     3     |     3     |     6     |    0
  null   |    B      |     4     |     0     |     1     |    1
   a     |    5      |     5     |     1     |     3     |    1
   b     |    4      |     6     |     2     |     5     |    1
   c     |    3      |     7     |     3     |     7     |    1

Pivot on Column6 with Values coming from Column2

Column1  |  Column3  |  Column4  |  Column5  |    0    |    1
-----------------------------------------------------------------
  null   |     0     |     0     |     0     |    A    |   null
  null   |     4     |     0     |     1     |   null  |    B
   a     |     1     |     1     |     2     |    2    |   null
   a     |     5     |     1     |     3     |   null  |    5
   b     |     2     |     2     |     4     |    1    |   null
   b     |     6     |     2     |     5     |   null  |    4
   c     |     3     |     3     |     6     |    6    |   null   
   c     |     7     |     3     |     7     |   null  |    3

Fill up (Column) 1

Column1  |  Column3  |  Column4  |  Column5  |    0    |    1
-----------------------------------------------------------------
  null   |     0     |     0     |     0     |    A    |    B
  null   |     4     |     0     |     1     |   null  |    B
   a     |     1     |     1     |     2     |    2    |    5
   a     |     5     |     1     |     3     |   null  |    5
   b     |     2     |     2     |     4     |    1    |    4
   b     |     6     |     2     |     5     |   null  |    4
   c     |     3     |     3     |     6     |    6    |    3   
   c     |     7     |     3     |     7     |   null  |    3

Filter (Column) 0 on null and remove Column3, Column4, and Column5 to get the final result

Column1  |    0    |    1
-----------------------------
  null   |    A    |    B
   a     |    2    |    5
   b     |    1    |    4
   c     |    6    |    3   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.