Forum Discussion

gaurav-narchal's avatar
5 years ago
Solved

Create Measure between Multiple tables

I want to create a measure to get the below result

 

Measure =  If Data Source (Serial No) & Amount Matches [tables] Table 1 (Serial No) & Amount or Table 2  (Serial No) & Amount or Table 3 (Serial No) & Amount or Table 4 (Serial No) & Amount return “ok” else “Error”

 

Then calculate the Amount difference and show in the last column

 

Result Display

SERIAL NOAMOUNTSTATUSAMOUNT DIFFERENCE
90909395601985OK0
90909395611985OK0
90909395621985OK0
90909395631985OK0
90909395644755OK0
90909395651170Error170
90909395661085OK0
90909395671855Error5
90909395702595OK0

 

Please find below the sample if this helps.

 

Click here PBIX

 

Thanks

Gaurav

  • ERD's avatar
    ERD
    5 years ago

    gaurav-narchal ,

    One of the ways is to use these measures (I assume your tables are connected via Serial No column):

     

    #check = 
    VAR _t = UNION('Table 1','Table 2','Table 3','Table 4')
    VAR amt = SUMX(_t, [AMOUNT])
    VAR dsAmt = SUM('Data Source'[AMOUNT])
    RETURN
    IF(dsAmt = amt, "OK", "Error")
    #diff = 
    VAR _t = UNION('Table 1','Table 2','Table 3','Table 4')
    VAR amt = SUMX(_t, [AMOUNT])
    VAR dsAmt = SUM('Data Source'[AMOUNT])
    RETURN
    IF([#check] = "Error", amt - dsAmt, 0)

     

    If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

  • ERD's avatar
    ERD
    5 years ago

    gaurav-narchal ,

    Please, check data types of the SN column in all tables. It should be whole number.

    Here I used another table without one of the values to make sure it works:

    If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

9 Replies

  • ERD's avatar
    ERD
    Community Champion

    Hi gaurav-narchal ,

    Do I understand correctly that Serial No from Data Source table can be met only at one of the tables?

    • Hi ERD - Yes Serial number from Data Source table can be met only at one of the tables. 

       

      Thank You.

      • ERD's avatar
        ERD
        Community Champion

        gaurav-narchal ,

        One of the ways is to use these measures (I assume your tables are connected via Serial No column):

         

        #check = 
        VAR _t = UNION('Table 1','Table 2','Table 3','Table 4')
        VAR amt = SUMX(_t, [AMOUNT])
        VAR dsAmt = SUM('Data Source'[AMOUNT])
        RETURN
        IF(dsAmt = amt, "OK", "Error")
        #diff = 
        VAR _t = UNION('Table 1','Table 2','Table 3','Table 4')
        VAR amt = SUMX(_t, [AMOUNT])
        VAR dsAmt = SUM('Data Source'[AMOUNT])
        RETURN
        IF([#check] = "Error", amt - dsAmt, 0)

         

        If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.