Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Sjmiller
Regular Visitor

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 servicelog was different than what they scheduled in the Appt table. So I will conditionally format those times.

This possible?

Difference2 =

VAR ApptValue =

SUMX(FILTER('Appts', 'Appts'[ApptDate] = MAX('LOG'[SRVDATE])), [Hours])

VAR SValue =

SUMX('LOG', [Hours])

RETURN

IF(ApptValue <> SValue, 1, 0)

The measure above works when it is a simple card visual, but when I add this measure to the matrix it does not work because of the filter context,
so I tried this measure, to account for that and its still marking everyone as 1.

Difference =

VAR ApptValue =

SUMX(

FILTER(

ALL('Appts'),

'Appts'[ApptDate] = MAX('LOG'[SRVDATE]) &&

'Appts'[custid] = SELECTEDVALUE('Appts'[custid]) &&

'Appts'[StaffName] = SELECTEDVALUE('Appts'[StaffName])

),

[Hours]

)

VAR SValue =

SUMX(

FILTER(

ALL('log'),

'Log'[cust_id] = SELECTEDVALUE('log'[cust_id]) &&

'Log'[StaffName] = SELECTEDVALUE('LOG'[StaffName])

),

[Hours]

)

RETURN

IF(ApptValue <> SValue, 1, 0)

1 ACCEPTED SOLUTION
swikritee_p
Resolver II
Resolver II

@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)

View solution in original post

2 REPLIES 2
swikritee_p
Resolver II
Resolver II

@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)

This worked thanks! 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.