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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Syndicate_Admin
Administrator
Administrator

Subtract rows from a table based on conditions indicated in another table

Good morning.

I have a table of transactions of different companies, these can make contracts between them (contracts table). I need to construct a table that shows me the result of these contracts as a difference of transactions between the buyer and seller (result table), as shown in the following image. Thanks for the support.

rpachecol_0-1653579396435.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rpachecol ,

 

Please try to create the following measure.

 

VALOR* =
SWITCH (
    MAX ( 'CONTRATOS'[CONTRATO] ),
    "EMPRESA 1-EMPRESA 2",
        CALCULATE (
            SUM ( 'TRANSACCIONES'[VALOR] ),
            FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 1" )
        )
            - CALCULATE (
                SUM ( 'TRANSACCIONES'[VALOR] ),
                FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 2" )
            ),
    "EMPRESA 2-EMPRESA 4",
        CALCULATE (
            SUM ( 'TRANSACCIONES'[VALOR] ),
            FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 2" )
        )
            - CALCULATE (
                SUM ( 'TRANSACCIONES'[VALOR] ),
                FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 4" )
            )
)

 

vstephenmsft_0-1654073124393.png

 

 

Best Regards,

Stephen Tao

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @rpachecol ,

 

Please try to create the following measure.

 

VALOR* =
SWITCH (
    MAX ( 'CONTRATOS'[CONTRATO] ),
    "EMPRESA 1-EMPRESA 2",
        CALCULATE (
            SUM ( 'TRANSACCIONES'[VALOR] ),
            FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 1" )
        )
            - CALCULATE (
                SUM ( 'TRANSACCIONES'[VALOR] ),
                FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 2" )
            ),
    "EMPRESA 2-EMPRESA 4",
        CALCULATE (
            SUM ( 'TRANSACCIONES'[VALOR] ),
            FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 2" )
        )
            - CALCULATE (
                SUM ( 'TRANSACCIONES'[VALOR] ),
                FILTER ( 'TRANSACCIONES', [EMPRESA] = "EMPRESA 4" )
            )
)

 

vstephenmsft_0-1654073124393.png

 

 

Best Regards,

Stephen Tao

 

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

freginier
Super User
Super User

You need to merge your data in power query

 

Two merges In Contract table add valor :

First merge to add Comprador Valor (link comprador - empresa)  

Second merge to add Vendedor Valor (link vendedor - empresa)

 

Then you should be able to substract values.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.