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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
samoberoi
Helper III
Helper III

Wrong subtraction results between two variables

Hi,

I am not getting the right subtraction results on subtracting the values derived from the two created variables based on some conditions. 

Please find the sample data with used measures and expected results here.

 

________________________________________________________________________________________________________________

TABLE B

 

Country

Tax Plan

Amount

England

BLL Type 2

159.46

England

BMM Type 5

2077.18

England

GL Type 1

52.52

England

GL Type 2

31685.68

England

IFTD Type 2

92

England

QTEL Type 2

878.86

England

QTEL Type 5

458.54

Wales

GL Type 1

-67

Wales

GL Type 2

2127.62

Wales

QTEL Type 2

8264.19


Table A 

 

Country

LType

Tax Plan

Amount

England

Type 1

GT Free Tax

-305

England

Type 2

GT Free Tax

350.62

England

Type 2

QT Free Tax

585.26

England

Type 5

QT Free Tax

137.56

England

Type 5

GT Free Tax

410.2

England

Type 5

QT Free Tax

2956.12

Wales

2013 boohoo

X Free G Tax

210

Wales

P-2013 boohoo

X Free G Tax

10

Wales

Type 2

QT Free Tax

104.56

Wales

Type 2

GT Free Tax

934.52

Wales

Type 2

QT Free Tax

1573

 

 

Measure used in Table B - Test = CALCULATE(

                                                           SUM('Table B'[Amount]),

                                                          FILTER(

                                                          'Table B',

                                                          'Table B'[Tax Plan] = "GL Type 1"

                                                           && 'Table B'[Country] in {"England","Wales"}))

 

 

Final results measure in Table A  - Subtraction_measure =

                                                                              VAR A =

                                                                                          CALCULATE(

                                                                                                    SUM('Table A'[Amount]),

                                                                                                               FILTER(

                                                                                                                      'Table A',

                                                                                                       ('Table A'[Country] = "England"

                                                                                                      && 'Table A'[LType] = "Type 2"

                                                                                                      && 'Table A'[Tax Plan] = "GT Free Tax")

                                                                                                      ||

                                                                                                     ('Table A'[Country] = "Wales"

                                                                                                    && 'Table A'[LType] = "Type 2"

                                                                                                   && 'Table A'[Tax Plan] = "QT Free Tax")))

           

                                                                                                    VAR B = [Test]

 

                                                                                                   RETURN

                                                                                                   B - A

 

 

Expected results looked for in the measure called "Subtraction_measure".

For Wales ----   1573+104.56 = 1677.56

                        -67-1677.56 = -1744.56


England ----    
52.52 - 350.62 =  -298.10

 

______________________________________________________________________________________________________________

Apologies, i tried to load the PBI file link here, but it didn't work; so i had to used this method of giving you sample data and expected results. For any help on this, it will be much appreciated.

 

TIA

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @samoberoi 

 

Thank you very much danextian for your prompt reply.

 

I did some testing and there doesn't seem to be anything wrong with your code. Running them individually gives the correct results, like this:

 

vnuocmsft_1-1736751177704.png

 

 

vnuocmsft_0-1736751049447.png

 

Do you want Subtraction_measure to display an equation? If so, you can use the following code:

 

Subtraction_measure = 
VAR A =
    CALCULATE(
        SUM('Table A'[Amount]),
        FILTER(
            'Table A',
            ('Table A'[Country] = "England"
            && 'Table A'[LType] = "Type 2"
            && 'Table A'[Tax Plan] = "GT Free Tax")
            ||
            ('Table A'[Country] = "Wales"
            && 'Table A'[LType] = "Type 2"
            && 'Table A'[Tax Plan] = "QT Free Tax")
        )
    )
VAR B = [Test]
VAR Result = B - A
RETURN
    FORMAT(B, "0.00") & " - " & FORMAT(A, "0.00") & " = " & FORMAT(Result, "0.00")

 

Here is the result.

vnuocmsft_2-1736751211803.png

 

If you still have questions, please provide your desired results. This is best presented in a table format.

 

Regards,

Nono Chen

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

4 REPLIES 4
Anonymous
Not applicable

Hi @samoberoi 

 

Thank you very much danextian for your prompt reply.

 

I did some testing and there doesn't seem to be anything wrong with your code. Running them individually gives the correct results, like this:

 

vnuocmsft_1-1736751177704.png

 

 

vnuocmsft_0-1736751049447.png

 

Do you want Subtraction_measure to display an equation? If so, you can use the following code:

 

Subtraction_measure = 
VAR A =
    CALCULATE(
        SUM('Table A'[Amount]),
        FILTER(
            'Table A',
            ('Table A'[Country] = "England"
            && 'Table A'[LType] = "Type 2"
            && 'Table A'[Tax Plan] = "GT Free Tax")
            ||
            ('Table A'[Country] = "Wales"
            && 'Table A'[LType] = "Type 2"
            && 'Table A'[Tax Plan] = "QT Free Tax")
        )
    )
VAR B = [Test]
VAR Result = B - A
RETURN
    FORMAT(B, "0.00") & " - " & FORMAT(A, "0.00") & " = " & FORMAT(Result, "0.00")

 

Here is the result.

vnuocmsft_2-1736751211803.png

 

If you still have questions, please provide your desired results. This is best presented in a table format.

 

Regards,

Nono Chen

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

Hi v-nuoc-msft,

Thank you for your help. It worked to some extent and solved the problem.
danextian
Super User
Super User

Hi @samoberoi 

 

This part of the test measure instructs DAX to filter countries in Table B that are either England or Wales. However, it does not direct DAX to return "England" or "Wales" if the current row's country in Table B is either England or Wales, as this tuple isn't related to Table B at all. As a result, the total of both countries is shown for each row.  Repalce that with  'Table B'[Country] IN VALUES('Table A'[Country])

'Table B'[Country] IN { "England", "Wales" }

danextian_0-1736655934107.png

 

Test =
CALCULATE (
    SUM ( 'Table B'[Amount] ),
    FILTER (
        'Table B',
        'Table B'[Tax Plan] = "GL Type 1"
            && 'Table B'[Country] IN { "England", "Wales" }
    )
)

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi, 

I tried to create the measure for table B as you advised; however, it is giving the same results as before and doesn't give any desired results, unless i am understanding something wrong.

Amended version of Table B - Test = CALCULATE(

                                                           SUM('Table B'[Amount]),

                                                          FILTER(

                                                          'Table B',

                                                          'Table B'[Tax Plan] = "GL Type 1"

                                                           && 'Table B'[Country] in values(Table A'[Country])

 

 

 

Let me show you the structure of my data model here. Sorry, i should have done it before.

samioberoi_0-1736700852871.png

 


Thanks for any help in advance.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.