Forum Discussion
combine 2 rows with m
I'm trying to clean up data that comes in ugly. Here is a sample:
DATE [space] multiplier [space] Description [hard return]
Value [hard return]
Repeat from here.
So, every two rows should actually be one row. I can split on the space delimiter to get my first 3 columns, but then, I can't get any farther. I have tried pivoting, but nothing seems to work.
I can make it work if I manually put the data in Word first and replace every other hard return with a space, but that really negates the idea of "automation."
I'd appreciate any and all help. I'm fairly decent with the GUI, but have only read M, haven't written any yet. I know SQL, DAX, and MDX, so it is only a matter of practice and time for M.
You can use this function: https://github.com/ImkeF/M/blob/master/Library/Table.PivotSingleColumn.pq
Just make sure that you get rid of the excess column name-rows. Your table must only contain values that shall go into the new columns.
In the 1st parameter you reference your table and in the 2nd you enter the number of new columns (2 or 4 according to your examples).
5 Replies
- Greg_DecklerCommunity Champion
Actual sample data would help tremendously. For hard M problems ImkeF is a genius.
- alwwebAdvocate II
I'm sorry, I don't see the option to attach files here, but you can find the sample file at https://www.dropbox.com/s/rwp61kaee8lihpg/Samples.xlsx?dl=0
I haven't done anything with these yet. The structure is a little different than my description, but close. On Sample1, other than the title which is easily handled, every two rows contain the values which should be a single row. On Sample2, there are 4 rows of column headings and then 4 rows for each record.
Unfortunately I can't simply look up the table from the web because I can't make the authentication work. Plus, I don't even know if it is written properly as a table for PowerQuery to recognize it.
- ImkeFCommunity Champion
You can use this function: https://github.com/ImkeF/M/blob/master/Library/Table.PivotSingleColumn.pq
Just make sure that you get rid of the excess column name-rows. Your table must only contain values that shall go into the new columns.
In the 1st parameter you reference your table and in the 2nd you enter the number of new columns (2 or 4 according to your examples).