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

How can I use Power Query to expand a cell into several rows?

Essentially, this is what I have:

 

YearCountyCityfatalitiespercentEmphasis_CategoryEmphasis_Area 
2010AdamsAdams-Unincorporated61.000TotalTotal 
2010BentonBenton-Unincorporated91.000TotalTotal 

 

And this is what I want to have:

 

YearCountyCityfatalitiespercentEmphasis_CategoryEmphasis_Area
2010AdamsAdams-Unincorporated11.000TotalTotal
2010AdamsAdams-Unincorporated11.000TotalTotal
2010AdamsAdams-Unincorporated11.000TotalTotal
2010AdamsAdams-Unincorporated11.000TotalTotal
2010AdamsAdams-Unincorporated11.000TotalTotal
2010AdamsAdams-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal
2010BentonBenton-Unincorporated11.000TotalTotal

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

Hi @streborxam 

Please refer to the following steps .

(1)Add a custom column .

Ailsamsft_0-1631601017630.png

Ailsamsft_1-1631601017632.png

(2)Expand the custom column .

Ailsamsft_2-1631601017635.png

(3)Remove the column [fatalities] and add a custom column rename it with same name [fatalities]

Ailsamsft_3-1631601017636.pngAilsamsft_4-1631601017639.png

(4) Remove the column [custom] and reorder the column [fatalities] in [City] and [percent] .

Ailsamsft_5-1631601017641.png

I have attached my pbix file , you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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-yetao1-msft
Community Support
Community Support

Hi @streborxam 

Please refer to the following steps .

(1)Add a custom column .

Ailsamsft_0-1631601017630.png

Ailsamsft_1-1631601017632.png

(2)Expand the custom column .

Ailsamsft_2-1631601017635.png

(3)Remove the column [fatalities] and add a custom column rename it with same name [fatalities]

Ailsamsft_3-1631601017636.pngAilsamsft_4-1631601017639.png

(4) Remove the column [custom] and reorder the column [fatalities] in [City] and [percent] .

Ailsamsft_5-1631601017641.png

I have attached my pbix file , you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

@streborxam here is one option

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNFDSUXJMScwthtG6oXmZecn5RQX5RYklqSlAYTMgNtQzMAApDckvScyB07E6cDOcUvNK8vPgDExTLHGbEgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ear = _t, County = _t, City = _t, fatalities = _t, percent = _t, Emphasis_Category = _t, Emphasis_Area = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"fatalities", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {1..[fatalities]}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded Custom",{"ear", "County", "City", "percent", "Emphasis_Category", "Emphasis_Area"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Other Columns", "fatalities", each 1),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom1",{"ear", "County", "City", "fatalities", "percent", "Emphasis_Category", "Emphasis_Area"})
in
    #"Reordered Columns"

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