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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Adoman
Frequent Visitor

Create a portfolio table from a buy and sell table

Hi All,

 

I have the following data that I put in to the table:

PortfolioIDSellerIDBuyerID
111155536112
111121185553
112355596088
182861693509;5375
24941672;60574062
296156495648
2500 4726
265361125026
11115553;61121433

This table contains Companies (PortfolioID) that are sold or bought by a PE Houses (Seller and Buyer). I would like to create a Portfolio table which contains only Buyers who did not sell a company and holds it. E.g.: the company 1111 should not be shown in portfolio of the PE House 6112. (bought in the first row and sold in the last row).

 

Any ideas how can I solved this Power Bi?

 

Thx

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@Adoman

 

At the very beginning, I think you'll have to re-model the data.

 

let
    Source = Table.FromRows({{1111 ,"5553", "6112"}, 
{1111 ,"2118", "5553"}, 
{1123 ,"5559", "6088"},
{1828 ,"6169", "3509;5375"}, 
{2494 ,"1672;6057", "4062"}, 
{2961 ,"5649", "5648"}, 
{2500 ,"","4726"},
{2653 ,"6112", "5026"}, 
{1111 ,"5553;6112", "1433"}},
{"PortfolioID", "SellerID" ,"BuyerID" } 
),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Index","SellerID",Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv),{"SellerID.1", "SellerID.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter","BuyerID",Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv),{"BuyerID.1", "BuyerID.2"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter1", {"PortfolioID", "SellerID.1", "SellerID.2", "Index"}, "Attribute", "Value"),
    #"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Unpivoted Columns", {"PortfolioID", "Index", "Attribute", "Value"}, "Attribute.1", "Value.1"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns1",{{"Value.1", "SellerID"}, {"Value", "BuyerID"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Attribute.1", "Attribute", "Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"PortfolioID", "SellerID", "BuyerID"})
in
    #"Reordered Columns"

Capture.PNG

 

 

Then a calculated table as

Table =
SUMMARIZE (
    FILTER (
        're-model table',
        IF (
            CONTAINS (
                FILTER (
                    CROSSJOIN (
                        SELECTCOLUMNS (
                            're-model table',
                            "PortfolioID", 're-model table'[PortfolioID],
                            "buyerid", 're-model table'[BuyerID],
                            "sellerid", 're-model table'[SellerID]
                        ),
                        SELECTCOLUMNS (
                            're-model table',
                            "PortfolioID2", 're-model table'[PortfolioID],
                            "buyerid2", 're-model table'[BuyerID],
                            "sellerid2", 're-model table'[SellerID]
                        )
                    ),
                    [PortfolioID] = [PortfolioID2]
                        && ( [buyerid] = [sellerid2]
                        || [sellerid] = [buyerid2] )
                ),
                [PortfolioID], 're-model table'[PortfolioID]
            ),
            FALSE (),
            TRUE ()
        )
    ),
    're-model table'[PortfolioID]
)

Capture.PNG

 

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@Adoman

 

At the very beginning, I think you'll have to re-model the data.

 

let
    Source = Table.FromRows({{1111 ,"5553", "6112"}, 
{1111 ,"2118", "5553"}, 
{1123 ,"5559", "6088"},
{1828 ,"6169", "3509;5375"}, 
{2494 ,"1672;6057", "4062"}, 
{2961 ,"5649", "5648"}, 
{2500 ,"","4726"},
{2653 ,"6112", "5026"}, 
{1111 ,"5553;6112", "1433"}},
{"PortfolioID", "SellerID" ,"BuyerID" } 
),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Index","SellerID",Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv),{"SellerID.1", "SellerID.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter","BuyerID",Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv),{"BuyerID.1", "BuyerID.2"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter1", {"PortfolioID", "SellerID.1", "SellerID.2", "Index"}, "Attribute", "Value"),
    #"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Unpivoted Columns", {"PortfolioID", "Index", "Attribute", "Value"}, "Attribute.1", "Value.1"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns1",{{"Value.1", "SellerID"}, {"Value", "BuyerID"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Attribute.1", "Attribute", "Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"PortfolioID", "SellerID", "BuyerID"})
in
    #"Reordered Columns"

Capture.PNG

 

 

Then a calculated table as

Table =
SUMMARIZE (
    FILTER (
        're-model table',
        IF (
            CONTAINS (
                FILTER (
                    CROSSJOIN (
                        SELECTCOLUMNS (
                            're-model table',
                            "PortfolioID", 're-model table'[PortfolioID],
                            "buyerid", 're-model table'[BuyerID],
                            "sellerid", 're-model table'[SellerID]
                        ),
                        SELECTCOLUMNS (
                            're-model table',
                            "PortfolioID2", 're-model table'[PortfolioID],
                            "buyerid2", 're-model table'[BuyerID],
                            "sellerid2", 're-model table'[SellerID]
                        )
                    ),
                    [PortfolioID] = [PortfolioID2]
                        && ( [buyerid] = [sellerid2]
                        || [sellerid] = [buyerid2] )
                ),
                [PortfolioID], 're-model table'[PortfolioID]
            ),
            FALSE (),
            TRUE ()
        )
    ),
    're-model table'[PortfolioID]
)

Capture.PNG

 

Thanks a lot, i really appreciate it.

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors