Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I'm fairly new to Power BI coming from a strong Excel VB coding background.
I need to move off Excel onto Power BI for a variety of corporate reasons, but how can I replicate the results of an Excel 'grouping' VB script I wrote, to an equivalent analysis result within Power BI?
In Excel we have a table with transactions on the Y axis in Col A (1 transaction per row) and for each transaction there may be one or many of the components which are listed on the x-axis in Row 1, used in each transaction, as determined by a '1' at the intersection of the transaction (row) and each component (column).
My (Excel) VB reads the name of each component used by each transaction and concatenates them as a list in a cell to the right of the last component column, so we can analyse which transactions used which components, and how often components are used together.
I need to somehow deliver something similar using Power BI, be it through using M or some other clever way.
Any suggestions from anyone?
Solved! Go to Solution.
Hi @Anonymous,
I believe you are looking for something like this:
Have a look at the following M code. This is a simple sketch built, mostly, using the PQ GUI.
It can probably be improved.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSQcKxOtFKRkgiYAFjGAemwgQhAOabwiRhCswQAmC+OVQxTN4CzleKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TransactionID = _t, ComponentA = _t, ComponentB = _t, ComponentC = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"TransactionID", Int64.Type}, {"ComponentA", Int64.Type}, {"ComponentB", Int64.Type}, {"ComponentC", Int64.Type}}),
Buffered = Table.Buffer(#"Changed Type"),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Buffered, {"TransactionID"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"TransactionID"}, {{"AttributeList", each _[Attribute], type list}}),
#"Extracted Values" = Table.TransformColumns(#"Grouped Rows", {"AttributeList", each Text.Combine(List.Transform(_, Text.From), " | "), type text}),
#"Merged Queries" = Table.NestedJoin(Buffered, {"TransactionID"}, #"Extracted Values", {"TransactionID"}, "Attributes", JoinKind.LeftOuter),
#"Expanded Attributes" = Table.ExpandTableColumn(#"Merged Queries", "Attributes", {"AttributeList"}, {"AttributeList"})
in
#"Expanded Attributes"
In case it answered your question please mark this as a solution to help other community members find it more easily.
Hi @Anonymous,
I believe you are looking for something like this:
Have a look at the following M code. This is a simple sketch built, mostly, using the PQ GUI.
It can probably be improved.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSQcKxOtFKRkgiYAFjGAemwgQhAOabwiRhCswQAmC+OVQxTN4CzleKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TransactionID = _t, ComponentA = _t, ComponentB = _t, ComponentC = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"TransactionID", Int64.Type}, {"ComponentA", Int64.Type}, {"ComponentB", Int64.Type}, {"ComponentC", Int64.Type}}),
Buffered = Table.Buffer(#"Changed Type"),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Buffered, {"TransactionID"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"TransactionID"}, {{"AttributeList", each _[Attribute], type list}}),
#"Extracted Values" = Table.TransformColumns(#"Grouped Rows", {"AttributeList", each Text.Combine(List.Transform(_, Text.From), " | "), type text}),
#"Merged Queries" = Table.NestedJoin(Buffered, {"TransactionID"}, #"Extracted Values", {"TransactionID"}, "Attributes", JoinKind.LeftOuter),
#"Expanded Attributes" = Table.ExpandTableColumn(#"Merged Queries", "Attributes", {"AttributeList"}, {"AttributeList"})
in
#"Expanded Attributes"
In case it answered your question please mark this as a solution to help other community members find it more easily.
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 |
User | Count |
---|---|
9 | |
7 | |
5 | |
4 | |
4 |