Forum Discussion
Awkward to Columnar - Filling a column values relatively placed in another column
Hi all,
I've got source data that comes in the following format:
ID XXXX
Date1 Val 1 Val 2 Val 3 Val 4 Val 5
Date2 Val 1 Val 2 Val 3 Val 4 Val 5
Date3 Val 1 Val 2 Val 3 Val 4 Val 5
ID YYYY
Date1 Val 1 Val 2 Val 3 Val 4 Val 5
Date2 Val 1 Val 2 Val 3 Val 4 Val 5
Date3 Val 1 Val 2 Val 3 Val 4 Val 5
ID ZZZZ
Date1 Val 1 Val 2 Val 3 Val 4 Val 5
Date2 Val 1 Val 2 Val 3 Val 4 Val 5
Date3 Val 1 Val 2 Val 3 Val 4 Val 5
And so on.
I want to transform this data into a continuous table in the following form:
ID Date
XXXX Date1 Val 1 Val 2 Val 3
XXXX Date2 Val 1 Val 2 Val 3
...
ID Date
YYYY Date1 Val 1 Val 2 Val 3
YYYY Date2 Val 1 Val 2 Val 3
So on.
Or, ideally, fully columnar, like so:
ID Date Data
XXXX Date1 Val 1
XXXX Date 1 Val 2
XXXX Date 2 Val 1
XXXX Date 2 Val 2
YYYY Date 1 Val1
YYYY Date 2 Val 2
And so on.
The stage I'm stuck on is dynamically labelling up all of the rows that belong to a certain ID.
My table currently looks like this:
Index Modulo IDCol Date Valu1 Valu2
1 1 XXXX
2 2 0 Date 1 Val 1 Val 2
3 3 0 Date 2 Val 1 Val 2
4 1 YYYY
5 2 0 Date1 Val 1 Val 2
6 3 0 Date2 Val 1 Val 2
...
I was able to pull across the ID from the awkwardly placed column above the values into an ID column of its own using a conditional column, but I'm not sure how to fill down the correct IDs (replacing the 0s) for all consecutive dates until the days or the modulo counter resets.
Could anyone help?
Let me know if I need to provide more detail.
- Anonymous7 years ago
Hi all - just to update, I managed to track down a solution.
If I changed my conditional column 'ID' to show null rather than '0' or blank ("") in the spaces between unique IDs (as per the screenshot in my reply here: https://community.powerbi.com/t5/Desktop/Awkward-to-Columnar-Filling-a-column-values-relatively-placed-in/m-p/605381/highlight/true#M288237), then I could simply use Fill -> Down to automatically replace all nulls with each consecutive non-null cell in the column.
Very clever, but not obvious at all as I tried filling down before and failed to get the right effect while I had '0' or "" in the empty fields.
12 Replies
- AnonymousNot applicable
i'm not 100% sure as I've never tested it, but have you tried with the "unpivot" feature?
- AnonymousNot applicable
Thanks for the suggestion.
Unpivot definitely looks like it will be part of the solution in terms of achieving the full columnar look and distribution, but it doesn't help me with correctly labelling up the data ranges associated with specific IDs.
The data is now basically:
ID
XXXX
0 Date1 Val1
0 Date1 Val2
0 Date2 Val1
0 Date2 Val2
YYYY
0 Date1 Val1
0 Date1 Val2
0 Date2 Val1
... so on.
Any ideas on how to fill down the IDs?
- AnonymousNot applicable
If this is your model of a set of rows
XXXX
0 Date1 Val1
0 Date1 Val2
0 Date2 Val1
0 Date2 Val2
and basically relying only on the "phisical order" to match the data, it's very dangerous. If that's what Unpivot does, then it's wrong.
Try to look at http://radacad.com/pivot-and-unpivot-with-power-bi