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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MegaOctane1
Helper I
Helper I

Compare two tables and return the lines that doesnt match but allow for a tolerance of 1 dollar

i have two tables with Inovicenumber, date and amount.
I compare the two tables, and get a result. But because of minor differences in amounts, the invoices still show up in the list. how can i get this to return only those with amount difference <>1 usd?

My DAX function:

InvoiceDifferences = 
    VAR __Table1 = SELECTCOLUMNS(Table1, "InvoiceNumber", [InvoiceNumber], "Amount", [Amount], "Date", [Date])
    VAR __Table2 = SELECTCOLUMNS(Table2,  "InvoiceNumber", [InvoiceNumber], "Amount", [Amount], "Date", [Date])
    VAR __Table1Except = EXCEPT(__Table1, __Table2)
    VAR __Table2Except = EXCEPT( __Table2, __Table1)

    VAR __Result = 
        FILTER(
                UNION(
                ADDCOLUMNS(  __Table1Except, "Source", "Table1"),
                ADDCOLUMNS( __Table2Except, "Source", "Table2")
            ),
        [Amount] <> 0 
        )
RETURN
__Result

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MegaOctane1 ,

Based on the information you have provided, I have created the following example to help you solve the problem and you can follow the steps below:
1. Append two tables and differentiate the data of the two tables, add an index column.

vyifanwmsft_0-1709194760895.png

 


2. Add two columns.

Table2difference = 
VAR _moverows =
    CALCULATE (
        COUNTROWS ( 'Table1' ),
        FILTER ( 'Table1', 'Table1'[Source] = EARLIER ( Table1[Source] ) )
    )
VAR _amount1 =
    CALCULATE (
        MAX ( 'Table1'[Amount] ),
        FILTER ( 'Table1', 'Table1'[Index] = EARLIER ( Table1[Index] ) - _moverows )
    )
VAR _difference =
    ABS ( 'Table1'[Amount] - _amount1 )
RETURN
    _difference
InvoiceDifferences = 
VAR _moverows =
    CALCULATE (
        COUNTROWS ( 'Table1' ),
        FILTER ( 'Table1', 'Table1'[Source] = EARLIER ( Table1[Source] ) )
    )
VAR _amount1 =
    CALCULATE (
        MAX ( 'Table1'[Table2difference] ),
        FILTER ( 'Table1', 'Table1'[Index] = EARLIER ( Table1[Index] ) + _moverows )
    )
RETURN
    IF ( 'Table1'[Source] = "Table2", 'Table1'[Table2difference], _amount1 )

3. Filter results with Flag=1.

vyifanwmsft_1-1709194925794.png

Final output:

vyifanwmsft_2-1709194956243.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

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

1 REPLY 1
Anonymous
Not applicable

Hi @MegaOctane1 ,

Based on the information you have provided, I have created the following example to help you solve the problem and you can follow the steps below:
1. Append two tables and differentiate the data of the two tables, add an index column.

vyifanwmsft_0-1709194760895.png

 


2. Add two columns.

Table2difference = 
VAR _moverows =
    CALCULATE (
        COUNTROWS ( 'Table1' ),
        FILTER ( 'Table1', 'Table1'[Source] = EARLIER ( Table1[Source] ) )
    )
VAR _amount1 =
    CALCULATE (
        MAX ( 'Table1'[Amount] ),
        FILTER ( 'Table1', 'Table1'[Index] = EARLIER ( Table1[Index] ) - _moverows )
    )
VAR _difference =
    ABS ( 'Table1'[Amount] - _amount1 )
RETURN
    _difference
InvoiceDifferences = 
VAR _moverows =
    CALCULATE (
        COUNTROWS ( 'Table1' ),
        FILTER ( 'Table1', 'Table1'[Source] = EARLIER ( Table1[Source] ) )
    )
VAR _amount1 =
    CALCULATE (
        MAX ( 'Table1'[Table2difference] ),
        FILTER ( 'Table1', 'Table1'[Index] = EARLIER ( Table1[Index] ) + _moverows )
    )
RETURN
    IF ( 'Table1'[Source] = "Table2", 'Table1'[Table2difference], _amount1 )

3. Filter results with Flag=1.

vyifanwmsft_1-1709194925794.png

Final output:

vyifanwmsft_2-1709194956243.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.