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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Equivalent result required in Power BI to what VB script achieves in Excel

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?

 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

Hi @Anonymous,

I believe you are looking for something like this:

SpartaBI_0-1651568626723.png


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. 

 

View solution in original post

1 REPLY 1
SpartaBI
Community Champion
Community Champion

Hi @Anonymous,

I believe you are looking for something like this:

SpartaBI_0-1651568626723.png


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. 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.