Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

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.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.


View solution in original post

12 REPLIES 12
Anonymous
Not applicable

i'm not 100% sure as I've never tested it, but have you tried with the "unpivot" feature?

Anonymous
Not 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?

Anonymous
Not 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

 

 

Anonymous
Not applicable

Well unfortunately my data comes in in this form:

 Property Address:Address   
 Property ID number:ID number   
      
DAY00:0000:3001:0001:3002:00
01-11-201819438.78919438.78919438.78919438.78919438.789
02-11-201819440.12219440.12219440.12219440.12219440.122
03-11-201819455.58219455.58219455.58219455.58219455.582
04-11-201819463.47219463.47219463.47219463.47219463.472
      
      
 Property Address:Address 2   
 Property ID number:ID number 2   
      
DAY00:0000:3001:0001:3002:00
01-11-201819330.84219330.84219330.84219330.84219330.842
02-11-201819332.14719332.14719332.14719332.14719332.147
03-11-201819345.82919345.82919345.82919345.82919345.829
04-11-201819353.22519353.22519353.22519353.22519353.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.

Anonymous
Not applicable

Is that an Excel?

Anonymous
Not applicable

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

Anonymous
Not applicable

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:

 

PQOutput.PNG

 

@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.

Anonymous
Not applicable

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 .

 

 

Anonymous
Not applicable

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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.