Forum Discussion

mahra-in's avatar
mahra-in
Helper II
8 years ago
Solved

Measure by comparing two columns in two different table

Hi   I need your help for the below   I have two tables with repeated values as below   Table 1: "Spend" (Excel Data)   Supplier Category Spend Weg Motor 5000 ABB ...
  • Anonymous's avatar
    Anonymous
    8 years ago

    This solution only requires Tables 1 and 2.  No bridge table, no relationships.

     

    Add this calculated column to Table 1 - Spend:

     

     

    Preferred =
    VAR Test =
        COUNTROWS (
            FILTER (
                PreferredSupplier,
                PreferredSupplier[Supplier] = Spend[Supplier]
                    && PreferredSupplier[Category] = Spend[Category]
            )
        )
    RETURN
        IF ( Test = 1, "Yes", "No" )

     

     

    The Test variable checks to see if there is a match against the Preferred Supplier table, matching both on Supplier and Category.  If there is, 1 row will be returned.   Then the result in the column will be "Yes".

     

    Then you can create the following measures:

     

    [Total Spend] =
    SUM ( Spend[Spend] )

     

    [Approved Spend] =
    CALCULATE ( [Total Spend], Spend[Preferred] = "Yes" )
    [% Approved Spend] =
    DIVIDE ( [Approved Spend], [Total Spend] )
  • mahra-in's avatar
    mahra-in
    8 years ago

    Hi ChrisHaas

     

    Your solution is working fine with small correction but I dont know why

     

    Preferred =
    VAR Test =
        COUNTROWS (
            FILTER (
                PreferredSupplier,
                PreferredSupplier[Supplier] = Spend[Supplier]
                    && PreferredSupplier[Category] = Spend[Category]
            )
        )
    RETURN
        IF ( Test = 1, "Yes", "No" )

     

    In the above calculated column I chnaged the If statement as

     

     IF ( Test = 0, "No", "Yes" )

     

    remining everything I keep as you mentioned and working perfect.

     

    But I said I still dont know what and why it gave wrong value first and right value once I changed the if statement

     

    Thanks for the solution, it works now