Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Calculation between 2 Tables - Relationships

Hi, I'm very new to Power Bi, so this might be an easy one for you.

 

I have a Table 1, which shows all customers entering a supermarket, on a given YYYYMM, and based on an irrelevant criteria, we classify them as a high spender or a low spender.

 

YYYYMMSpendVolume of Customers
201701High35
201701Low22
201702High28
201702Low24
201703High47
201703Low51
201704High33
201704Low31

 

I also have a Table 2, which shows all customers in the supermarket that have bought Apples. They are shown not as total number of customers but as individual entries for each customer.

 

YYYYMMSpendGood BoughtCustomer Name
201701HighAppleJohn
201701LowAppleMartha
201701LowAppleMichael
201701LowAppleJane
201701LowAppleMoody
201701HighApplePaul
201701HighAppleColin

 

I want to figure out how many customers bought Apples as a percentage of how many customers entered the Supermarket, classified as High or Low spenders. 

This is the output I want:

201701HighApples20%
201701LowApples35%
201702HighApples15%
201702LowApples45%

 

I joined the two tables on YYYYMM, but when I do the following function:

 

Apples Pct = countrows(Table2)/sum(Table1[Volume of Customers])

 

I get the right aggregated percentage. But when I try inserting 'Good Bought' in Rows, my count for High and Low shows up the same as the Total value.

YYYYMMSpend 
201704High64
201704Low64
Total 64

 

When I try building relationships for Spend between the 2 Tables, it gives me an error for ambiguity.

Any advice?

  • Hi Anonymous 

    I get different percentages but I'm not sure whether it is because I've understood incorrectly what you need or  because you made a mistake in the numbers you show. In any case, try this (see it all at work in the attached file)

    1. Create this measure:

    MeasureCount = COUNT(Table2[Customer Name])
    2. Create this other measure based on the previous one:
    MeasureTotal =
    DIVIDE (
        [MeasureCount];
        CALCULATE (
            SUM ( Table1[Volume of Customers] );
            FILTER (
                Table1;
                Table1[YYYYMM] = SELECTEDVALUE ( Table2[YYYYMM] )
                    && Table1[Spend] = SELECTEDVALUE ( Table2[Spend] )
            )
        )
    )

    3. Place Table2[YYYYMM], Table[Spend] and Table2[Good Bought] in values of a table visual. Make sure they all are set to 'Don't summarize'.

    4. Place both [MeasureCount] and [MesureTotal] in the table visual

     

2 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi Anonymous 

    I get different percentages but I'm not sure whether it is because I've understood incorrectly what you need or  because you made a mistake in the numbers you show. In any case, try this (see it all at work in the attached file)

    1. Create this measure:

    MeasureCount = COUNT(Table2[Customer Name])
    2. Create this other measure based on the previous one:
    MeasureTotal =
    DIVIDE (
        [MeasureCount];
        CALCULATE (
            SUM ( Table1[Volume of Customers] );
            FILTER (
                Table1;
                Table1[YYYYMM] = SELECTEDVALUE ( Table2[YYYYMM] )
                    && Table1[Spend] = SELECTEDVALUE ( Table2[Spend] )
            )
        )
    )

    3. Place Table2[YYYYMM], Table[Spend] and Table2[Good Bought] in values of a table visual. Make sure they all are set to 'Don't summarize'.

    4. Place both [MeasureCount] and [MesureTotal] in the table visual

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Not all heroes wear capes...

       

      Thank you!