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

Similar columns in single table and need guidance on how to handle

Background & Sample Data:

We have data coming in from a single SharePoint list that has multiple transactions on a single row/record for each team.

Record IDTeamTrans 1 IDTrans 1 Date Trans 1 CostTrans 2 IDTrans 2 DateTrans 2 CostTrans 3 IDTrans 3 DateTrans 3 Cost
1Team A456541/5/2019$1,342.22156874/26/2019$7,964.504589710/10/2019$111.12
2Team B489962/5/2019$900.00654893/11/2020$121.84   
3Team C987642/7/2019$143.55254896/1/2019$2,319.10   
4Team D781364/15/2019$684.99636327/6/2019$75.88665461/5/2020$600.01

Issues & Questions

In an ideal world, I'd think the data would be best arranged with each transaction listed as an individual row/record. We'd then have a single Trans Date, Trans Cost, and Trans ID column instead of these being repeated across multiple columns. 

 

Since this isn't our world, what is the best way to go about handling data like this? Our actual data has even more transaction columns repeated (~50 trans total per record). Is there a way to combine columns (e.g. Trans 1 Date, Trans 2 Date, etc.) into a single column (Trans Dates)? Is that even what we should be looking to do? A bit lost with the current format and what we should do to change and shape it into something usable for creating reports/dashboards in Power BI. Any and all guidance and help is greatly appreciated.

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

Hi @dsever04 ,

Please follow steps as shown below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZA9bgQhDIWvskIpkeEZMHaZnyOkG02RImXu38YmO+xKkUBYfuazn48jIeX0+f31c3v1oA8Z3V+UUbjCPHxBbp2JOdJDdEZZYdn6zCadRl3f1UJHLX42ACBwOvOR+Gr2FtVqJv7yUzOrlWqgfA6NTCuAq1wXiUEa8932DWq7qO8emE7pizofE/RGY0TyTpWCLXJuMEL9h+0X9sODqWiyrOMxrWgnW7wmLbzN8rSXQaqhuRXZO/0zImET6Tx/AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Record ID" = _t, Team = _t, #"Trans 1 ID" = _t, #"Trans 1 Date " = _t, #"Trans 1 Cost" = _t, #"Trans 2 ID" = _t, #"Trans 2 Date" = _t, #"Trans 2 Cost" = _t, #"Trans 3 ID" = _t, #"Trans 3 Date" = _t, #"Trans 3 Cost" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Record ID", Int64.Type}, {"Team", type text}, {"Trans 1 ID", Int64.Type}, {"Trans 1 Date ", type date}, {"Trans 1 Cost", Currency.Type}, {"Trans 2 ID", Int64.Type}, {"Trans 2 Date", type date}, {"Trans 2 Cost", Currency.Type}, {"Trans 3 ID", Int64.Type}, {"Trans 3 Date", type date}, {"Trans 3 Cost", Currency.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Record ID", "Team"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3", "Attribute.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}, {"Attribute.3", type text}, {"Attribute.4", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute.1", "Attribute.2", "Attribute.4"}),
    #"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[Attribute.3]), "Attribute.3", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns1"

10.29.4.2.gif

Here is the pbix file.

 

https://kohera.be/blog/power-bi/how-to-unpivot-twice/

https://community.powerbi.com/t5/Power-Query/Expression-Error-There-were-too-many-elements-in-the-en...

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

View solution in original post

3 REPLIES 3
v-eqin-msft
Community Support
Community Support

Hi @dsever04 ,

Please follow steps as shown below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZA9bgQhDIWvskIpkeEZMHaZnyOkG02RImXu38YmO+xKkUBYfuazn48jIeX0+f31c3v1oA8Z3V+UUbjCPHxBbp2JOdJDdEZZYdn6zCadRl3f1UJHLX42ACBwOvOR+Gr2FtVqJv7yUzOrlWqgfA6NTCuAq1wXiUEa8932DWq7qO8emE7pizofE/RGY0TyTpWCLXJuMEL9h+0X9sODqWiyrOMxrWgnW7wmLbzN8rSXQaqhuRXZO/0zImET6Tx/AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Record ID" = _t, Team = _t, #"Trans 1 ID" = _t, #"Trans 1 Date " = _t, #"Trans 1 Cost" = _t, #"Trans 2 ID" = _t, #"Trans 2 Date" = _t, #"Trans 2 Cost" = _t, #"Trans 3 ID" = _t, #"Trans 3 Date" = _t, #"Trans 3 Cost" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Record ID", Int64.Type}, {"Team", type text}, {"Trans 1 ID", Int64.Type}, {"Trans 1 Date ", type date}, {"Trans 1 Cost", Currency.Type}, {"Trans 2 ID", Int64.Type}, {"Trans 2 Date", type date}, {"Trans 2 Cost", Currency.Type}, {"Trans 3 ID", Int64.Type}, {"Trans 3 Date", type date}, {"Trans 3 Cost", Currency.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Record ID", "Team"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3", "Attribute.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}, {"Attribute.3", type text}, {"Attribute.4", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute.1", "Attribute.2", "Attribute.4"}),
    #"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[Attribute.3]), "Attribute.3", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns1"

10.29.4.2.gif

Here is the pbix file.

 

https://kohera.be/blog/power-bi/how-to-unpivot-twice/

https://community.powerbi.com/t5/Power-Query/Expression-Error-There-were-too-many-elements-in-the-en...

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

HotChilli
Super User
Super User

@dsever04 

 

If you select the first 2 columns and 'Unpivot other columns'

You should now have 4 columns.  You want to split the 3rd ('attribute' column) by delimiter (space) so that you can retain the numeral column and the column with ID, Date, Cost.

Remove the column with 'Trans' in it and any other null columns.

You should have 5 columns now.

Pivot on the  column with ID, Date, Cost,    using Value as the Values column.  Choose 'Don't aggregate' in the advanced section.

Filter out the null values in the ID column.

That should work

DataInsights
Super User
Super User

@dsever04,

 

You can unpivot each set of columns (e.g., Trans 1) using the technique below.

 

https://datachant.com/2019/10/11/guest-story-unpivot-pairs-of-columns/ 





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

Proud to be a Super User!




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.