Forum Discussion

BoCoKeith's avatar
BoCoKeith
New Member
6 years ago
Solved

Count Customers by Product in Order/LineItem Structure

I think I'm missing something fundamental.  Given this PowerBI data model:     I'm trying to build a matrix showing the number of customers that have purchased a particular product.  The tab...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi BoCoKeith 

    If you change the relationship from single to both, you will find the answer is correct.

    But Both direction is not recommended in Power BI. So you may try to use measure or merge to achieve your goal.

    Measure:

    Discount CustomerID = CALCULATE(DISTINCTCOUNT(temp_Order[CustomerId]),CROSSFILTER(temp_LineItem[OrderId],temp_Order[OrderId],Both))

    Result:

    Merge:

    Select Merge Queries as New.

    1.  Merge temp_Product and temp_LineItem by ProductID column in each table

    2.  Merge New Table and temp_Order by OrderID column in each table. 

    The Final table is as below.

    Result:


    You can download the pbix file from this link: Count Customers by Product in Order/LineItem Structure

     

    Best Regards,

    Rico Zhou

     

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