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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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?

1 ACCEPTED SOLUTION
AlB
Super User
Super User

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

 

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

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
Not applicable

Not all heroes wear capes...

 

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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