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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jeggen
Helper II
Helper II

Unpivot data and combine by year

This seems like it should be simple but can't figure it out.

 

I need to unpivot my data from this:

Customer IDYear 1 RevenueYear 1 CategoryYear 2 RevenueYear 2 CategoryYear 3 RevenueYear 3 Category
1313468C2483B456B
2374B9187B3417B
3428246C371304C977A

 

To this:

Cutomer IDYearRevenue

Customer

Category

11313468C
21374B
31428246C
122483B
229187B
32371304C
13456B
233417B
33977A

 

I assume there is some intervening step wehre my data would retain the original column headers that I would need to clean up that might look something like this.

Cutomer IDLabel 1Label 2RevenueRevenue Category
1Year 1 RevenueYear 1 Category313468C
2Year 1 RevenueYear 1 Category374B
3Year 1 RevenueYear 1 Category428246C
1Year 2 RevenueYear 2 Category2483B
2Year 2 RevenueYear 2 Category9187B
3Year 2 RevenueYear 2 Category371304C
1Year 3 RevenueYear 3 Category456B
2Year 3 RevenueYear 3 Category3417B
3Year 3 RevenueYear 3 Category977A

 

If I can get this far I can cleanup to get the above table. I can't figure out how to pivot into this in way that keeps the years together across one line. Any suggestions on how to unpivot this data to get basically three lines for each customer, one per year, with corresponding revenue and category for that donor and year combination?

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

You won't get that 'intermediate' table.

Unpivot everything apart from Customer ID.

Split the Attribute column so that you get a column with  only 'Revenue' or 'Category' in it.

Pivot that column with the Value as Values.  Use "Don't Aggregate"

That should be it.

Let me know.

View solution in original post

3 REPLIES 3
ThxAlot
Super User
Super User

Nothing to do with pivoting,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PYyxDcAwCAR3oXYR4GNwmWQMxP5rBEcoxYt7cRBBTIOUFdMLnorAtcZdwTk/yhEk2zP0ZrFbo4Ltt/YlxAWzv6mxHuiybJsXZb4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer ID" = _t, #"Year 1 Revenue" = _t, #"Year 1 Category" = _t, #"Year 2 Revenue" = _t, #"Year 2 Category" = _t, #"Year 3 Revenue" = _t, #"Year 3 Category" = _t]),
    Cols = Table.ToColumns(Source),
    Yearly = let customer = Cols{0} in List.Transform(List.Split(List.Skip(Cols), 2), each Table.FromColumns({customer} & _, {"Customer","Revenue","Category"})),
    ToTable = Table.FromColumns({{1 .. List.Count(Yearly)}, Yearly},{"Year","yearly"}),
    #"Expanded yearly" = Table.ExpandTableColumn(ToTable, "yearly", {"Customer", "Revenue", "Category"})
in
    #"Expanded yearly"

ThxAlot_0-1717708100223.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



jeggen
Helper II
Helper II

Worked perfectly, thank you!

HotChilli
Super User
Super User

You won't get that 'intermediate' table.

Unpivot everything apart from Customer ID.

Split the Attribute column so that you get a column with  only 'Revenue' or 'Category' in it.

Pivot that column with the Value as Values.  Use "Don't Aggregate"

That should be it.

Let me know.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors