Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a file in this format
| Level1 | Level2 | Level3 | Level4 |
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 2 |
| 1 | 2 | 2 | 3 |
| 1 | 2 | 2 | 4 |
| 1 | 2 | 3 | 4 |
and want to convert it to this format
| Id | ParentId |
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
anyone know of an easy way to do this?
I don't understand your data. Why does the same number appear on multiple levels on the same line? Why do all IDs have the same parent?
Do you mean you want to do this:
| ID | ParentID |
|---|---|
| 1 | 1 |
| 1 | 1 |
| 1 | 1 |
| 1 | 1 |
| 1 | 1 |
| 2 | 1 |
| 2 | 1 |
| 2 | 2 |
| 2 | 2 |
| 2 | 2 |
| 3 | 1 |
| 3 | 1 |
| 3 | 2 |
| 3 | 2 |
| 3 | 3 |
| 4 | 1 |
| 4 | 2 |
| 4 | 3 |
| 4 | 3 |
| 4 | 4 |
It's just random data. Ill post an example of the real info.
On Dec 27, 2011, at 7:09 PM, John Witherspoon <
Yes, that's the format I need to end up with.
Sent from my iPad
On Dec 27, 2011, at 7:49 PM, "B.Sarcich" <
You could do something like this:
RAW:
LOAD * INLINE [
Level1, Level2, Level3, Level4
1, 1, 1, 1
1, 1, 1, 2
1, 2, 2, 3
1, 2, 2, 4
1, 2, 3, 4
];FOR EACH FieldNo IN '1', '2', '3', '4'
LET FieldName = 'Level' & '$(FieldNo)';
ID_LIST:
LOAD
$(FieldNo) As ID,
$(FieldName) As ParentID
RESIDENT RAW;NEXT FieldNo
RAW can be loaded from an excel file or wherever else. I am assuming here that the field names are Level1, Level2 etc. This example is of course not dynamic; you must know how many fields there are and code that into the FOR EACH section. Possibly you can come up with a way to dynamically put that into a variable and put the variable after the IN.
Someone else can probably come up with a smarter way to do this than me anyway.