Forum Discussion

datamodel's avatar
datamodel
Advocate I
6 years ago

Another crossjoin question

In the following activity table, I would like to get a count of all products that interacted with eachother under activity types 7,8,and15.

 

CustomerIDProductIDActivityTypeID
1238887
1238888
12378915
45678887
456777715
456799915
45679998

 

(pivot on related table Product)

ProductProductInteractions(number of products interacted with across all customers)
8883(interacted with products 789 on customer 123, and 777 and 999 on customer 4567)
7772(interacted with products 888 on customer 4567 and 999 on customer 4567)
9992(interacted with products 777 on customer 4567 and 888 on customer 4567)
7891(interacted with products 888 on customer 123)

 

(pivot on related table Customer)

CustomerProductInteractions(number of products interacted for all customers)
1232(888 and 789 interacted with eachother)
45673(888, 777, and 999 interacted with eachother)

 

(pivot on related tables Customer and Product)

CustomerProductProductInteractions(number of products interacted with eachother at customer/product level)
1238881(1 interaction for 789)
1237891(1 interaction for 888)
45678882(1 interaction for 777 and 1 for 999)
45677772(1 interaction for 888 and 1 for 999)
45679992(1 interaction for 777 and 1 for 888)

 

1 Reply

  • Hi datamodel ,

    In order to achieve the effect you want, you need 3 measures:

    1. pivot on related table Product

    pivot on related table Product =
    VAR _table =
        CALCULATETABLE ( VALUES ( 'Table'[CustomerID] ) )
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[ProductID] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[CustomerID] IN _table )
        ) - 1

    2. pivot on related table Customer

    pivot on related table Customer =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[ProductID] ) )

    3. pivot on related tables Customer and Product

    pivot on related tables Customer and Product =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ProductID] ),
        FILTER (
            ALLSELECTED ( 'Table'[ProductID] ),
            'Table'[ProductID] <> MAX ( 'Table'[ProductID] )
        )
    )

    Results are as follows:

     

    Here is a demo, please try it

    https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ERhkafE6NNtLnzro0aJi2CgBqV_S7dTIUxUIQWL2dCgIlg?e=VEhtTU

     

    Best Regards,

    Community Support Team _ Joey
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.