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.
Morning,
Updated 9/6
I currently have a large number of rows which are the result of un-nesting from a json file. I would like to be unpivot two groups of rows as so instead of there simply being one long row per TransactionID there are multiple rows with the same TransactionID but different ItemName category groups.
At the moment, there are seven ItemName category groups (ItemName1, ItemName2) which have the same columns names, structures and types but are only differentiated by their respective ItemName, for example ItemName1, ItemName2, ItemName3.
I would like there to be a maximum of 7 rows for each permanent grouping, which have the same permanent column groups and only different values from the different ItemName clusters. After we've completed this in powerquery, I would then like to remove the rows which contain a "null" ItemName*ItemID value. So there could be up to seven rows where the permanent grouping of columns (will list below) remain the same, but the values in the variable columns (will list below) are filled by the values from the seven different ItemName clusters.
Permanent Columns (same for each row) in the unpivot:
TransactionID | list_merchant_id | list_creator_id | DateTime | list_tender_type | list_tender_name | list_tender_id | list_tender_total_money_amount | list_tender_tendered_money_amount | list_tender_change_back_money_amount | list_tender_refunded_money_amount | list_refunds_type | list_refunds_created_at | list_refunds_processed_at | list_refunds_reason | list_refunds_refunded_money_amount | list_refunds_payment_id | list_refunds_merchant_id | list_refunds_refunded_processing_fee_money_amount | list_refunds_refunded_additive_tax_money_amount | list_refunds_refunded_inclusive_tax_money_amount | list_refunds_refunded_tip_money_amount | list_refunds_refunded_discount_money_amount |
These are the first 23 columns in the excel file.
Variable Columns (same column names with subtle difference of number for grouping, but the values which are different for each unpivot'ed rows):
ItemName1Notes | ItemName1Quantity | ItemName1 | ItemName1Category | ItemName1Sku | ItemName1ItemID | ItemName1VariationID | Item Name1DiscountAmount | Sales1 | ItemName1DiscountAmount | ItemName1Modifier1Name | ItemName1Modifier1Amount | ItemName1Modifier1ID | list_itemizations_itemization_type | ItemName1Modifier2Name | ItemName1Modifier2Amount | ItemName1Modifier2ID | ItemName1Modifier3Name | ItemName1Modifier3Amount | ItemName1Modifier3ID | ItemName1Modifier4Name | ItemName1Modifier4Amount | ItemName1Modifier4ID | ItemName1Modifier5Name | ItemName1Modifier5Amount | ItemName1Modifier5ID
|
These are the next 26 columns in the excel file.
I have attached the pbix and the excel file.
In the excel file, Sheet One contains the table structure and the data examples. Sheet Two contains an example of how I would like the data to be pivoted to.
Pbix and Excel File Link: https://1drv.ms/f/s!At8Q-ZbRnAj8hl4QQ9aqeygF46VF
@MarcelBeug has posted a lot about this and I feel his solutions are the right idea and direction. I'll post links and ideas later tonight.
Solved! Go to Solution.
You can easily combine the different queries into 1:
let FixedParts = List.Transform({1..7}, each "Modifier"&Text.From(_))&{ "ItemName", "Item Name", "Notes", "Quantity", "Category", "Sku", "ItemID", "VariationID", "Sales", "DiscountAmount", "Discount", "Name", "Amount", "ID", "list_itemizations_itemization_type"}, Source = Excel.Workbook(File.Contents("C:\Users\Marcel\Documents\Forum bijdragen\Power BI Community\Elliot 20170609\unpivotdatastructure.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers","NULL",null,Replacer.ReplaceValue,Table.ColumnNames(#"Promoted Headers")), First23columnNames = List.FirstN(Table.ColumnNames(#"Replaced Value"),23), Unpivot = Table.UnpivotOtherColumns(#"Replaced Value", First23columnNames, "Attribute", "Value"), VariableParts = Table.AddColumn(Unpivot, "VariableParts", each List.Select(Splitter.SplitTextByAnyDelimiter(FixedParts)([Attribute]), each _ <> "")), #"Added Custom" = Table.AddColumn(VariableParts, "FixedPart", each Text.Combine(List.Select(Splitter.SplitTextByEachDelimiter([VariableParts])([Attribute]), each _ <> ""))), #"Trimmed Text" = Table.TransformColumns(#"Added Custom",{{"VariableParts", Text.Combine, type text}}), #"Removed Columns" = Table.RemoveColumns(#"Trimmed Text",{"Attribute"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[FixedPart]), "FixedPart", "Value"), #"Filtered Rows" = Table.SelectRows(#"Pivoted Column", each [VariableParts] >= "1" and [VariableParts] <= "7") in #"Filtered Rows"
Once your source data is correct, you probably won't need the last step anymore.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
106 | |
88 | |
74 | |
69 |
User | Count |
---|---|
123 | |
112 | |
95 | |
83 | |
73 |