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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
alwweb
Advocate II
Advocate II

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.

1 ACCEPTED SOLUTION

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

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Actual sample data would help tremendously. For hard M problems @ImkeF is a genius.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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.

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

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thank you! You truly are a genius.  I haven't had time to download and apply it yet, but just looking at the code I can tell that it is exactly what I need.  

 

Do you have a blog site or anything or do you spend all your "spare" time answering questions and helping people here?

 

You just made my life much easier.  Again, thank you!

Thank you @alwweb 🙂

I'm blogging here: www.TheBIccountant.com

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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