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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
mash7432
New Member

Pivot Column with Don't aggregate - Multiple Rows

I currently have data with an "Activity" column that contains a combination of 'activities' and 'sub-activities'. I need activities and sub-activities in their own columns, with each row representing a single sub-activity.

 

Sample data:

WorkstreamPhaseActivityActivity LevelHelper
WS1P1A11A
WS1P1SA12A
WS1P1SA22A
WS1P1A21B
WS1P1SA32B

 

Desired output:

WorkstreamPhaseActivitySub-Activity
WS1P1A1SA1
WS1P1A1SA2
WS1P1A2SA3

 

I tried to Pivot the Activity Level column, using Activity as the value and "don't aggregate" but I run into an error when there is more than 1 sub-activity.

 

Thanks for your help!

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@mash7432,

 

Try this in Power Query. Copy the code starting with ChangeType and paste into your query editor. This solution assumes that subactivities are listed below the activity to which they relate.

 

let
  Source = Table.FromRows(
      Json.Document(
          Binary.Decompress(
              Binary.FromText(
                  "i45WCg82VNJRCgARjiACzFCK1UGRCQZLGWGXMsIlBZYBMZwwNRlDNQGlYgE=", 
                  BinaryEncoding.Base64
                ), 
              Compression.Deflate
            )
        ), 
      let
        _t = ((type nullable text) meta [Serialized.Text = true])
      in
        type table [Workstream = _t, Phase = _t, Activity = _t, #"Activity Level" = _t, Helper = _t]
    ),
  ChangeType = Table.TransformColumnTypes(Source, {{"Activity Level", Int64.Type}}),
  AddColumn = Table.AddColumn(
      ChangeType, 
      "Activity Parent", 
      each if [Activity Level] = 2 then null else [Activity]
    ),
  FillDown = Table.FillDown(AddColumn, {"Activity Parent"}),
  FilterRows = Table.SelectRows(FillDown, each ([Activity Level] = 2)),
  ChangeType2 = Table.TransformColumnTypes(FilterRows, {{"Activity Parent", type text}}),
  RenameColumns = Table.RenameColumns(
      ChangeType2, 
      {{"Activity", "Subactivity"}, {"Activity Parent", "Activity"}}
    )
in
  RenameColumns

 

 

DataInsights_0-1604616247199.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@mash7432,

 

Try this in Power Query. Copy the code starting with ChangeType and paste into your query editor. This solution assumes that subactivities are listed below the activity to which they relate.

 

let
  Source = Table.FromRows(
      Json.Document(
          Binary.Decompress(
              Binary.FromText(
                  "i45WCg82VNJRCgARjiACzFCK1UGRCQZLGWGXMsIlBZYBMZwwNRlDNQGlYgE=", 
                  BinaryEncoding.Base64
                ), 
              Compression.Deflate
            )
        ), 
      let
        _t = ((type nullable text) meta [Serialized.Text = true])
      in
        type table [Workstream = _t, Phase = _t, Activity = _t, #"Activity Level" = _t, Helper = _t]
    ),
  ChangeType = Table.TransformColumnTypes(Source, {{"Activity Level", Int64.Type}}),
  AddColumn = Table.AddColumn(
      ChangeType, 
      "Activity Parent", 
      each if [Activity Level] = 2 then null else [Activity]
    ),
  FillDown = Table.FillDown(AddColumn, {"Activity Parent"}),
  FilterRows = Table.SelectRows(FillDown, each ([Activity Level] = 2)),
  ChangeType2 = Table.TransformColumnTypes(FilterRows, {{"Activity Parent", type text}}),
  RenameColumns = Table.RenameColumns(
      ChangeType2, 
      {{"Activity", "Subactivity"}, {"Activity Parent", "Activity"}}
    )
in
  RenameColumns

 

 

DataInsights_0-1604616247199.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors