Forum Discussion

Sjmiller's avatar
Sjmiller
Regular Visitor
2 years ago
Solved

Difference between tables

Two table difference I am trying to calculate the difference between two tables that are only related to each other on date. The ultimate goal is to find the times where the actual time used in the ...
  • swikritee_p's avatar
    2 years ago

    Sjmiller , check if this code can help

    Difference = 
    VAR CurrentDate = SELECTEDVALUE('LOG'[SRVDATE])
    VAR CurrentCustID = SELECTEDVALUE('LOG'[cust_id])
    VAR CurrentStaffName = SELECTEDVALUE('LOG'[StaffName])
    
    VAR ApptValue = 
        CALCULATE(
            SUM('Appts'[Hours]),
            FILTER(
                'Appts',
                'Appts'[ApptDate] = CurrentDate &&
                'Appts'[custid] = CurrentCustID &&
                'Appts'[StaffName] = CurrentStaffName
            )
        )
    
    VAR SValue = 
        CALCULATE(
            SUM('LOG'[Hours]),
            FILTER(
                'LOG',
                'LOG'[SRVDATE] = CurrentDate &&
                'LOG'[cust_id] = CurrentCustID &&
                'LOG'[StaffName] = CurrentStaffName
            )
        )
    
    RETURN IF(ApptValue <> SValue, 1, 0)