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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.