Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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.
Solved! Go to Solution.
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-plac...), 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.
i'm not 100% sure as I've never tested it, but have you tried with the "unpivot" feature?
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?
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
Well unfortunately my data comes in in this form:
Property Address: | Address | ||||
Property ID number: | ID number | ||||
DAY | 00:00 | 00:30 | 01:00 | 01:30 | 02:00 |
01-11-2018 | 19438.789 | 19438.789 | 19438.789 | 19438.789 | 19438.789 |
02-11-2018 | 19440.122 | 19440.122 | 19440.122 | 19440.122 | 19440.122 |
03-11-2018 | 19455.582 | 19455.582 | 19455.582 | 19455.582 | 19455.582 |
04-11-2018 | 19463.472 | 19463.472 | 19463.472 | 19463.472 | 19463.472 |
Property Address: | Address 2 | ||||
Property ID number: | ID number 2 | ||||
DAY | 00:00 | 00:30 | 01:00 | 01:30 | 02:00 |
01-11-2018 | 19330.842 | 19330.842 | 19330.842 | 19330.842 | 19330.842 |
02-11-2018 | 19332.147 | 19332.147 | 19332.147 | 19332.147 | 19332.147 |
03-11-2018 | 19345.829 | 19345.829 | 19345.829 | 19345.829 | 19345.829 |
04-11-2018 | 19353.225 | 19353.225 | 19353.225 | 19353.225 | 19353.225 |
Where, as you can see, the ID is not associated with each of the rows of data pertaining to it.
As a result, my first challenge is to just fill down the ID against each of the tabular sets of data.
Once I have done that, unpivot should work as intended, I think.
It's probably just my lack of experience with the Query Editor, but I've been stuck for a neat way of doing this for a few days now - any help would be appreciated.
Is that an Excel?
The source is an Excel file, yes.
But it comes in 50k rows at a time, hence why I'm looking for a Query Editor way of sorting it out into a workable format.
In that scenario I have often cheated and created a hidden sheet in the Excel which uses formulas to "normalise" the data before import, that may not work in your case if you have lots of different 50k files
Thanks for weighing in guys.
I'd be really surprised if this couldn't be reliably processed in the Query Editor or M directly.
Surely there must be a way!
I'm so close and yet so far away:
@Anonymous i'm confident that this can be achieved using PQ. If you share your data in excel it will help to get you the solution.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Thanks for the suggestion, here's a link to a reduced verison of my source file: link removed as solution was found.
You should be able to download a good copy from there .
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-plac...), 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.
@Anonymous
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
95 | |
76 | |
65 | |
51 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |