Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Slicing Calculated Column Sums Using Nested Relation

I'm making a report for displaying equipment parts. Part of that is displaying the count of the parts per piece of equipment and the total cost of replacement associated with them. I have a table with the equipment names (there are duplicate names because they're associated with child data), a table that has each parts associated with their parent equipment, and a parts table that has distinct values. It looks like this: 

Machines Table Machine-Part Table PartData Table
Machine MachinePart PartQuantity (Calculated Column)
1 1CA CA 
2 1CA CB 
3 1CB CC 
4Relation1CBRelationCD 
5Many:Many1CBMany:OneCE 
6 2CC CF 
7 2CC CG 
8 2CC CH 
9 2CD CI 
10 2CD CJ 
11 3CA CK 
12 3CA CL 
13 3CB CM 
14 3CB CN 
15 3CB CO 
    

I have a table visual that shows the part data and a slicer that filters it using "Machine" from the Machines Table. Some machines share parts with other machines. For the quantity column, I take the count of that part from the second table, filtered by the Machine Name selected in a slicer. However, it doesn't count based on the Machine name; if I select Machine 1, which is identical to Machine 3, it returns the sum of parts for both, whether either or both are selected. It does filter the table to only show the parts inside that Machine (so something's working). The quantities need help though. However, I can't add a condition to the filter for the COUNT where Machines Table[Machine] = Machine-PartTable[Machine] (probably because they're already related).

I've tried ALLSELECTED and USERELATIONSIP but they both return the same incorrect behavior. Here's what I have:

 
Part Quantity=
CALCULATE(
    COUNT('Machine-PartTable'[Part]),
        FILTER(ALLSELECTED('Machine-PartTable'),
            'Machine-PartTable'[Part] = 'Part-DataTable'[Part]
        )
    )

 

I do apologize if this has already been answered, I couldn't find a similar enough topic. Thanks in advance for any advice/wisdom.

8 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Somewhat, yes. However, in the table, I'm trying to achieve:

      1. Each part associated with a machine to be present

      2. The quantity of that part in the selected machine 

       

      So I'm only doing this with a single slicer based on the Machine Name. The problem I'm having is that my slicer doesn't seem to be filtering down to the Part table, only the MachineToPart table. I changed your file to illustrate and attached it with a drive link - I ungrouped rows in MachineToPart, changed your measure to use COUNT(), and deleted the Part slicer. Somehow, these changes have got it working as I desired, but I have no clue why. It's against everything I've found to be consistent in PowerBI so far (and I wouldn't mind an explanation).

       

      Machines And Parts Mod

      • Anonymous's avatar
        Anonymous
        Not applicable
        Hi there.

        Well, you have changed only the MachineToPart table but the change is completely inessential from the point of view of functionality. What you've done is you've only expanded the table making it bigger. But the size will be felt only when the table has millions of rows.

        I don't understand why you should expand the table since the compact one returns exactly the same results.

        Your COUNT( MachineToPart[Part] ) is achievable through COUNTROWS( MachineToPart ).

        I don't understand what's really different from the solution I originally posted. I can't see any difference.

        The selection of a machine name from the dimension does not filter to the Part dimension because for this to be the case you'd need to change the connection between MachineToPart and Part to be two-way. But two-way cross-filtering is dangerous and should not be used unless strictly necessary.

        Best
        D