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

Calculated Measures based on conditions across tables

Hi!

This report will show a car shop how they can save of parts by switching suppliers and/or negotiating. 

I am needing to create the following calculations from the data below:

 

1) Cost Savings for Same Part, Same Supplier

2) Savings from Same Part Different Supplier

3)Saving based on Alternate Part, Same Supplier

4) Savings based on Alternate Part, Alternate Supplier

 

(Table A)

There is a shop that is looking at their data for a year, they can see what parts they bought, from which supplier, and how much each part costs. 

 

(Table B) 

This table shows how much that same part is being sold, on average across different suppliers.

 

(Table C)

This table shows alternate parts, the supplier, and its average price. 

 

A

PrimaryPartConcatPartSupplierAVGCostEach
1105065 NAPA CLUTCHESSupplier 4$125.53
52641404 VALEOSupplier 1$130.00
MU18901D PERFECTION CLUTCHSupplier 5$138.53

 

B

PrimaryPartConcatPartSupplierAVGCostEach
05065 LUK AUTOMOTIVE SYSTEMSSupplier 1$139.99
05065 LUK AUTOMOTIVE SYSTEMSSupplier 3$143.53

 

C

PrimaryPartConcatPartSupplierAVGCostEach
1105065 NAPA CLUTCHESSupplier 4$125.53
52641404 VALEOSupplier 1$130.00
MU18901D PERFECTION CLUTCHSupplier 5$138.53
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I build three tables like yours to have a test.

TableA:

1.png

TableB:

2.png

TableC (I add an Alternate Part column in this table):

3.png

1.     Cost Savings for Same Part, Same Supplier (output the smaller avg in A/B with same part and same supplier with A)

 

1_Avg = 
VAR _MinAvg_B =
    CALCULATE (
        MIN ( B[AVGCostEach] ),
        FILTER ( B, B[PartSupplier] = MAX ( A[PartSupplier] ) && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_B, SUM ( A[AVGCostEach] ), _MinAvg_B )

 

Result:

4.png

2.     Savings from Same Part Different Supplier (output the smaller avg and the new supplier in A/B with same part and different supplier with A)

 

2_Supplier = 
VAR _MinAvg_B =
    CALCULATE (
        MIN ( B[AVGCostEach] ),
        FILTER (
            B,
            B[PartSupplier] <> MAX ( A[PartSupplier] )
                && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )
        )
    )
RETURN
    IF (
        _MinAvg_B = BLANK (),
        MAX ( A[PartSupplier] ),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_B,
            MAX ( A[PartSupplier] ),
            CALCULATE (
                MAX ( B[PartSupplier] ),
                FILTER (
                    B,
                    B[PartSupplier] <> MAX ( A[PartSupplier] )
                        && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )&&B[AVGCostEach]=_MinAvg_B
                )
            )
        )
    )
2_Avg = 
VAR _MinAvg_B =
    CALCULATE (
        MIN ( B[AVGCostEach] ),
        FILTER (
            B,
            B[PartSupplier] <> MAX ( A[PartSupplier] )
                && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )
        )
    )
RETURN
    IF (
        _MinAvg_B = BLANK (),
        SUM ( A[AVGCostEach] ),
        IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_B, SUM ( A[AVGCostEach] ), _MinAvg_B )
    )

 

Result:

5.png

3.     Saving based on Alternate Part, Same Supplier (output the smaller avg and the Ap in A/C with alternate part and same supplier with A)

 

3_AP = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] = MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF (
        _MinAvg_C = BLANK (),
        BLANK (),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_C,
            BLANK (),
            CALCULATE (
                MAX ( C[Alternate Part] ),
                    FILTER ( C, C[PartSupplier] = MAX ( A[PartSupplier] ) &&  C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )  )
                )
        )
)
3_Avg = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] = MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF(_MinAvg_C=BLANK(), SUM ( A[AVGCostEach] ),
    IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_C, SUM ( A[AVGCostEach] ), _MinAvg_C ))

 

Result:

6.png

4.     Savings based on Alternate Part, Alternate Supplier (output the smaller avg and the Ap/new supplier in C with alternate part and different supplier with A)

 

4_Supplier = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF (
        _MinAvg_C = BLANK (),
        MAX(A[PartSupplier]),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_C,
            MAX(A[PartSupplier]),
                       CALCULATE (
                MAX ( C[PartSupplier] ),
                    FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) && C[AVGCostEach]=_MinAvg_C)
                )
        )
)
4_AP = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF (
        _MinAvg_C = BLANK (),
        BLANK (),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_C,
            BLANK (),
            CALCULATE (
                MAX ( C[Alternate Part] ),
                    FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
                )
        )
)
4_Avg = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF(_MinAvg_C=BLANK(), SUM ( A[AVGCostEach] ),
    IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_C, SUM ( A[AVGCostEach] ), _MinAvg_C ))

 

Result:

7.png

If this reply still couldnt help you to solve your problem, please provide me the complete data or provide me with your pbix file by onedrive for business.

You can download the pbix file from this link: Calculated Measures based on conditions across tables

 

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. 

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I build three tables like yours to have a test.

TableA:

1.png

TableB:

2.png

TableC (I add an Alternate Part column in this table):

3.png

1.     Cost Savings for Same Part, Same Supplier (output the smaller avg in A/B with same part and same supplier with A)

 

1_Avg = 
VAR _MinAvg_B =
    CALCULATE (
        MIN ( B[AVGCostEach] ),
        FILTER ( B, B[PartSupplier] = MAX ( A[PartSupplier] ) && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_B, SUM ( A[AVGCostEach] ), _MinAvg_B )

 

Result:

4.png

2.     Savings from Same Part Different Supplier (output the smaller avg and the new supplier in A/B with same part and different supplier with A)

 

2_Supplier = 
VAR _MinAvg_B =
    CALCULATE (
        MIN ( B[AVGCostEach] ),
        FILTER (
            B,
            B[PartSupplier] <> MAX ( A[PartSupplier] )
                && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )
        )
    )
RETURN
    IF (
        _MinAvg_B = BLANK (),
        MAX ( A[PartSupplier] ),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_B,
            MAX ( A[PartSupplier] ),
            CALCULATE (
                MAX ( B[PartSupplier] ),
                FILTER (
                    B,
                    B[PartSupplier] <> MAX ( A[PartSupplier] )
                        && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )&&B[AVGCostEach]=_MinAvg_B
                )
            )
        )
    )
2_Avg = 
VAR _MinAvg_B =
    CALCULATE (
        MIN ( B[AVGCostEach] ),
        FILTER (
            B,
            B[PartSupplier] <> MAX ( A[PartSupplier] )
                && B[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )
        )
    )
RETURN
    IF (
        _MinAvg_B = BLANK (),
        SUM ( A[AVGCostEach] ),
        IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_B, SUM ( A[AVGCostEach] ), _MinAvg_B )
    )

 

Result:

5.png

3.     Saving based on Alternate Part, Same Supplier (output the smaller avg and the Ap in A/C with alternate part and same supplier with A)

 

3_AP = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] = MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF (
        _MinAvg_C = BLANK (),
        BLANK (),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_C,
            BLANK (),
            CALCULATE (
                MAX ( C[Alternate Part] ),
                    FILTER ( C, C[PartSupplier] = MAX ( A[PartSupplier] ) &&  C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] )  )
                )
        )
)
3_Avg = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] = MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF(_MinAvg_C=BLANK(), SUM ( A[AVGCostEach] ),
    IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_C, SUM ( A[AVGCostEach] ), _MinAvg_C ))

 

Result:

6.png

4.     Savings based on Alternate Part, Alternate Supplier (output the smaller avg and the Ap/new supplier in C with alternate part and different supplier with A)

 

4_Supplier = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF (
        _MinAvg_C = BLANK (),
        MAX(A[PartSupplier]),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_C,
            MAX(A[PartSupplier]),
                       CALCULATE (
                MAX ( C[PartSupplier] ),
                    FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) && C[AVGCostEach]=_MinAvg_C)
                )
        )
)
4_AP = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF (
        _MinAvg_C = BLANK (),
        BLANK (),
        IF (
            SUM ( A[AVGCostEach] ) <= _MinAvg_C,
            BLANK (),
            CALCULATE (
                MAX ( C[Alternate Part] ),
                    FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
                )
        )
)
4_Avg = 
VAR _MinAvg_C =
    CALCULATE (
        MIN ( C[AVGCostEach] ),
        FILTER ( C, C[PartSupplier] <> MAX ( A[PartSupplier] ) && C[PrimaryPartConcat] = MAX ( A[PrimaryPartConcat] ) )
    )
RETURN
    IF(_MinAvg_C=BLANK(), SUM ( A[AVGCostEach] ),
    IF ( SUM ( A[AVGCostEach] ) <= _MinAvg_C, SUM ( A[AVGCostEach] ), _MinAvg_C ))

 

Result:

7.png

If this reply still couldnt help you to solve your problem, please provide me the complete data or provide me with your pbix file by onedrive for business.

You can download the pbix file from this link: Calculated Measures based on conditions across tables

 

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. 

Anonymous
Not applicable

Thank you @v-rzhou-msft !

I created the individual measures, but when I try putting them into a table for totals, the grand total is wrong. I tried creating this summary table, but it is not working right. Any suggestion?

 

Summary Savings = 
SUMMARIZE('Shop Details','Shop Details'[PrimaryPartColumn],
"Cost Savings 1st" , ([1. Measure for Cost Savings]),
"Cost Savings 2nd" , ([2. Measure for Cost Savings]),
"Cost Savings 3rd" , ([3. Measure for Cost Savings]),
"Cost Savings 4th" , ([4. Measure for Cost Savings]),
)

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.