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

Require help with data re-organisation, unpivot columns options with a slight twist.

I have data in somthing like this, upto Dec in each category. every month a fresh report will come for about 1500 items under category. Using unpivot for the data columns I just feel the no of columns go up significantly. 

 

  ValueQtyValueQty
category abc2024Jan 24Feb 24Mar 24Jan 24Feb 24Mar 24Jan 25Feb 25Mar 25Jan 25Feb 25Mar 25
apple 123456789101112
orange 123456789101112
grapes 12345678

9

101112

 

I'm think if I can organise data in the following format can help me reduce no. of rows as the category I'm handling is about 1500 and the report will be published monthly so data will keep on adding. I'm open to any other suggestions on managing such data.

 

category Reporting MonthMonthValue 2024Value 2025Qty 2024Qty 2025
appleJan 24Jan17410
appleJan 24Feb28511
appleJan 24Mar39612
OrangeJan 24Jan17410
OrangeJan 24feb28511
OrangeJan 24mar39612
grapesJan 24Jan17410
grapesJan 24feb28511
grapesJan 24mar39612
appleFeb 24Jan    
appleFeb 24Feb    
appleFeb 24Mar    
OrangeFeb 24Jan    
OrangeFeb 24Feb    
OrangeFeb 24Mar    
grapesFeb 24Jan    
grapesFeb 24Feb    
grapesFeb 24Mar    

 

appreciate any thoughts or insights and options to explore, somthing I don't need to carry many operations each month and be more sustainable byitself except adding fresh data each month.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MKY 

Based on your description , I create the following code and you can refer to(Note: In your original table, you don't have the report month field, so I don't create it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSiwoyElV0lFSAGJDIDYCYmMgNgFiUyA2A2JzILYAYkuQGgMQAVJpaKQUqxOtlF+UmJdOkQnpRYkFqcVkmxALAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"category " = _t, abc2024 = _t, #"Jan 24" = _t, #"Feb 24" = _t, #"Mar 24" = _t, #"Jan 24.1" = _t, #"Feb 24.1" = _t, #"Mar 24.1" = _t, #"Jan 25" = _t, #"Feb 25" = _t, #"Mar 25" = _t, #"Jan 25.1" = _t, #"Feb 25.1" = _t, #"Mar 25.1" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Jan 24", Int64.Type}, {"Feb 24", Int64.Type}, {"Mar 24", Int64.Type}, {"Jan 24.1", Int64.Type}, {"Feb 24.1", Int64.Type}, {"Mar 24.1", Int64.Type}, {"Jan 25", Int64.Type}, {"Feb 25", Int64.Type}, {"Mar 25", Int64.Type}, {"Jan 25.1", Int64.Type}, {"Feb 25.1", Int64.Type}, {"Mar 25.1", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"abc2024"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"category "}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
    #"Replaced Value" = Table.ReplaceValue(#"Split Column by Delimiter",each [Attribute.2],each if Text.Contains([Attribute.2],"." )then "Qty"&" "&[Attribute.2] else "Value"&" "&[Attribute.2],Replacer.ReplaceValue,{"Attribute.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Replaced Value", "Attribute.2", Splitter.SplitTextByEachDelimiter({"."}, QuoteStyle.Csv, false), {"Attribute.2.1", "Attribute.2.2"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Split Column by Delimiter1",{"Attribute.2.2"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Attribute.2.1]), "Attribute.2.1", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.1", "Month"}})
in
    #"Renamed Columns"

Output

vxinruzhumsft_0-1711506771745.png

 

Best Regards!

Yolo Zhu

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

6 REPLIES 6
Anonymous
Not applicable

Hi @MKY 

Based on your description , I create the following code and you can refer to(Note: In your original table, you don't have the report month field, so I don't create it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSiwoyElV0lFSAGJDIDYCYmMgNgFiUyA2A2JzILYAYkuQGgMQAVJpaKQUqxOtlF+UmJdOkQnpRYkFqcVkmxALAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"category " = _t, abc2024 = _t, #"Jan 24" = _t, #"Feb 24" = _t, #"Mar 24" = _t, #"Jan 24.1" = _t, #"Feb 24.1" = _t, #"Mar 24.1" = _t, #"Jan 25" = _t, #"Feb 25" = _t, #"Mar 25" = _t, #"Jan 25.1" = _t, #"Feb 25.1" = _t, #"Mar 25.1" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Jan 24", Int64.Type}, {"Feb 24", Int64.Type}, {"Mar 24", Int64.Type}, {"Jan 24.1", Int64.Type}, {"Feb 24.1", Int64.Type}, {"Mar 24.1", Int64.Type}, {"Jan 25", Int64.Type}, {"Feb 25", Int64.Type}, {"Mar 25", Int64.Type}, {"Jan 25.1", Int64.Type}, {"Feb 25.1", Int64.Type}, {"Mar 25.1", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"abc2024"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"category "}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
    #"Replaced Value" = Table.ReplaceValue(#"Split Column by Delimiter",each [Attribute.2],each if Text.Contains([Attribute.2],"." )then "Qty"&" "&[Attribute.2] else "Value"&" "&[Attribute.2],Replacer.ReplaceValue,{"Attribute.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Replaced Value", "Attribute.2", Splitter.SplitTextByEachDelimiter({"."}, QuoteStyle.Csv, false), {"Attribute.2.1", "Attribute.2.2"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Split Column by Delimiter1",{"Attribute.2.2"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Attribute.2.1]), "Attribute.2.1", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.1", "Month"}})
in
    #"Renamed Columns"

Output

vxinruzhumsft_0-1711506771745.png

 

Best Regards!

Yolo Zhu

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

 

MKY
Frequent Visitor

Ho Yolo, this is impressive. Thanks a lot. I'm planning to start with unpivot option to check if it can resolve, else what you have shared is what I was looking for. I might contact you again when I further do the deep dive into this option.

RossEdwards
Solution Sage
Solution Sage

In my opinion, your original method is correct.  Unpivot the data and let Power BI deal with having lots of rows.  Aggregating data is what Power BI is good at. It can handle millions of rows without a sweat.  Just make sure your model is a star schema and you have the appropriate dimensional tables to get the best performance.

You should be able to let power query handle your dynamically changing data and unpivot without issues.  The new method you seem to be talking about seems like it will create unncessary admin overhead.

Hi Ross, Thanks a lot, I also felt that to be a preferred option. couple of linked doubts I am not sure on how to handle were:

  1. How best to label each column, such that charts can easily be prepared mainly on month basis. would there be issues if I use Value_Jan2024, will the system be still able to consider as time? can I still calculate YTD or cummulative data month on month? ( I could use addition function as a work around but not sure in built YTD functions can be used)
  2. Since each month I get a fresh report that includes data for the 12 months (YTD+YTG). each month expected to compare current changes compared to last month.
  3. analyse YTD & YTG against annual plan etc.

So any suggestions on how to label columns that would make life easier would be great.

Assuming you have a reliable consistency in your values, after unpivoting i'd create a "date" column and use the function Date.FromText.  This date can be linked to a date table for time intelligent reporting.

Hi Ross, unfortunately the data doesn't has a date field in any column. I was thinking of including a month field column when the report is created (monthly) like Jan_IBP2024, Feb_IBP2024 and so on....Would you suggest that I rather use 'Jan2024'? Is there a way to use this field to calculate YTD and YTG. For example a report created for Feb2024 has actual of Jan & Feb (YTD) and Forecast for remaining 10 months (YTG). I would like to be able to use and present data each month as spliet of YTD & YTG. each month's report an additional actual month's data will be included.

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
Top Kudoed Authors