Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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:
| Workstream | Phase | Activity | Activity Level | Helper |
| WS1 | P1 | A1 | 1 | A |
| WS1 | P1 | SA1 | 2 | A |
| WS1 | P1 | SA2 | 2 | A |
| WS1 | P1 | A2 | 1 | B |
| WS1 | P1 | SA3 | 2 | B |
Desired output:
| Workstream | Phase | Activity | Sub-Activity |
| WS1 | P1 | A1 | SA1 |
| WS1 | P1 | A1 | SA2 |
| WS1 | P1 | A2 | SA3 |
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!
Solved! Go to Solution.
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
Proud to be a Super User!
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
Proud to be a Super User!
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 104 | |
| 82 | |
| 72 | |
| 46 | |
| 35 |