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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
powerbi2srm
Resolver II
Resolver II

Comparación de columnas de distintas tablas bajo una condición

Hola,
Estoy tratando de comparar los importes de las facturas de dos programas para ver cuáles no coinciden. Cada programa está en una tabla:
- account_invoice_programaA

- account_invoice_programa_B
Ambas están relacionadas por un campo llamado: id_programaA.

Quiero ignorar las diferencias de hasta 5 céntimos, para lo que he utilizado el siguiente código:

Num distintos importes = 
CALCULATE(
    COUNT(account_invoice_programaB[id_programaA]),
    FILTER(
        account_invoice_programaB,
        ROUND(account_invoice_programaB[importe_programaB],2) <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) - 0.01 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) - 0.02 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) - 0.03 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) - 0.04 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&  
        ROUND(account_invoice_programaB[importe_programaB],2) - 0.05 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&  
        ROUND(account_invoice_programaB[importe_programaB],2) + 0.01 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) && 
        ROUND(account_invoice_programaB[importe_programaB],2) + 0.02 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) + 0.03 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) + 0.04 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2) &&
        ROUND(account_invoice_programaB[importe_programaB],2) + 0.05 <> ROUND(RELATED(account_invoice_programaA[importe_programaA]),2)
    ),
    USERELATIONSHIP(dim_date[date_id], account_invoice_programaA[programaA_invoice_date_id])
)

Sin embargo, cuando pongo en una visualización las facturas, compruebo como aparecen muchas con 0,01€ y 0,02€ de diferencia entre importes, por lo que el código no está funcionando correctamente. ¿Alguien sabe qué puede estar ocurriendo? Muchas gracias!
1 ACCEPTED SOLUTION
powerbi2srm
Resolver II
Resolver II

Solución
CALCULATE
(
    DISTINCTCOUNTNOBLANK(account_invoice_programaB[id_programaA]),
    FILTER(
        account_invoice_programaB,
        ABS(account_invoice_programaB[importe_programaB] - RELATED(account_invoice_programaA[importe_programaB]))>0.05
    ),
    USERELATIONSHIP(dim_date[date_id], account_invoice_programaA[programaA_invoice_date_id])
)

View solution in original post

1 REPLY 1
powerbi2srm
Resolver II
Resolver II

Solución
CALCULATE
(
    DISTINCTCOUNTNOBLANK(account_invoice_programaB[id_programaA]),
    FILTER(
        account_invoice_programaB,
        ABS(account_invoice_programaB[importe_programaB] - RELATED(account_invoice_programaA[importe_programaB]))>0.05
    ),
    USERELATIONSHIP(dim_date[date_id], account_invoice_programaA[programaA_invoice_date_id])
)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.