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
ptewary
Frequent Visitor

Consolidate multiple columns to two columns

Hi there,

 

I have a dataset like the following:

 

RecipeIngredient 1Ingredient 2Ingredient 3Ingredient 4Measure 1Measure 2Measure 3 Measure 4
R1I11I12I13I14M11M12M13M14
R2I21I22  M21M22  
R3I31I32I33I34M31M32M33M34
R4I41I42I43 M41M42M43 
R5I51I52I53 M51M52M53 

 

I want there to be just a single column for ingredients and a single column for the corresponding measures, like below:

 

RecipeIngredientMeasure
R1I11M11
R1I12M12
R1I13M13
R1I14M14
R2I21M21
R2I22M22
R3I31M31
R3I32M32
R3I33M33
R3I34M34
R4I41M41
R4I42M42
R4I43M43
R5I51M51
R5I52M52
R5I53M53

 

How can I achieve this in Power Query? Please let me know if any other clarification is needed.

 

Thanks in advance!

1 ACCEPTED SOLUTION

@ptewary 

 

Try this Custom Column. Then expand it to new rows

Please see attached file with your data and steps

 

=let 
ingredients=List.Select(Table.ColumnNames(#"Changed Type"),each Text.StartsWith(_,"Ingredient")),
measures=List.Select(Table.ColumnNames(#"Changed Type"),each Text.StartsWith(_,"Measure"))
in
#table({"Ingredients","MEASURES"},
List.Zip({
Record.ToList(
Record.SelectFields(_,ingredients)),
Record.ToList(
Record.SelectFields(_,measures))}))

 


Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
mussaenda
Super User
Super User

Measure is from data or you created it using DAX?


@mussaenda wrote:

Measure is from data or you created it using DAX?


The Measure columns are from the data itself. The data is basically like: Ingredient 1 = "Salt", Measure 1 = "1 Tbsp"; Ingredient 2 = "Chicken", Measure 2 = "1 whole"; etc...

@ptewary 

 

Try this Custom Column. Then expand it to new rows

Please see attached file with your data and steps

 

=let 
ingredients=List.Select(Table.ColumnNames(#"Changed Type"),each Text.StartsWith(_,"Ingredient")),
measures=List.Select(Table.ColumnNames(#"Changed Type"),each Text.StartsWith(_,"Measure"))
in
#table({"Ingredients","MEASURES"},
List.Zip({
Record.ToList(
Record.SelectFields(_,ingredients)),
Record.ToList(
Record.SelectFields(_,measures))}))

 


Regards
Zubair

Please try my custom visuals

Thanks a lot - works perfectly!

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.