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

Merge alternative columns dynamically used in a function

Hi,

 

So I have this data in multiple files in a folder. The data is formated in the following way:

First column: Date and time

Second column: Measured value of series 1

Third column: Status of measured value  series 1

Forth column: Measure value of series 2

Fifth column: Status value of series 2

 

Sample:

TimestampValue 1Status 1Value 2Status 2   ...Value NStatus N
2017-12-01 00:004Calculated3  1 
2017-12-01 01:003Calculated2Estimated 6 
2017-12-01 02:002Calculated6  8Calculated
2017-12-01 03:000Calculated8  5Calculated

 

 

The amount of columns is dependent on how many series is in that file. I would like to make a function to clean and make the data neat for all the files in the folder. I do this by merging the column Measured value and Status and then splitting it and normalizing it. But since the data has different amount of columns cross the files I'm having a hard time creating a function for this. Anybody have any good suggestions to create a function to merge every other column except the first one, independent on number of columns? 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

If all files in a folder have the same format, you could Get Data from Folder with Power BI,

Then Click Edit, expand the "Content"

7.png

 

Select "Source.Name" and "Timestamp" columns and unpivot other columns

8.png

Rename the "Value" column to "combine Status"

9.png

Spilt the "Attribute" column 

10.png

rename "Attribute.2" to "Series"

Select ""Attribute.2" and pivot columns

11.png

 

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

If all files in a folder have the same format, you could Get Data from Folder with Power BI,

Then Click Edit, expand the "Content"

7.png

 

Select "Source.Name" and "Timestamp" columns and unpivot other columns

8.png

Rename the "Value" column to "combine Status"

9.png

Spilt the "Attribute" column 

10.png

rename "Attribute.2" to "Series"

Select ""Attribute.2" and pivot columns

11.png

 

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous,

you've already get a solution from @v-juanli-msft.

But an alternative could be using functions like Table.ColumnNames or Record.FieldNames. You get a list of all columns of a table or a record which you can filter with List.Select. And then you can do your magic. It expects more programming skills in M.

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.

Top Solution Authors
Top Kudoed Authors