Forum Discussion

powerbi2srm's avatar
powerbi2srm
Resolver II
3 years ago

CALCULAR VALORES DISTINTOS DE DOS TABLAS

Hola!

 

Quiero calcular el número de valores que no coinciden entre dos columnas de dos tablas diferentes.

En mi caso, tengo una tabla de facturas (fact_sale_invoice) y otra de ventas (fact_sale_order) relacionadas a través de una tabla intermedia (rel_sale_order_invoice). Quiero hallar cuántos valores hay distintos entre las columnas de extended_amount de ambas tablas:

 

Esto es lo que he intentado, aunque de forma fallida (soy nuevo en esto y no estoy muy seguro del uso de SELECTEDVALUE): 

 

PV_descuadrados =
IF(
    SELECTEDVALUE(fact_sale_order[sales_amount])<>SELECTEDVALUE(fact_sale_invoice[invoice_amount]),
    COUNT(fact_sale_order[sale_order_id]),
    0
)

 

 

Gracias!!

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  powerbi2srm ,

    I created some data:

    Table1:

    Table2:

    Intermediate tables:

    Directly in the measure using two columns for comparison, there may be a Cartesian product, you can consider doing it in the calculated column.

    Here are the steps you can follow:

    1. Create calculated column.

    Create calculated column pull indexes in two tables:

    Table1Index =
    SUMX(FILTER(ALL('Intermediate tables'),'Intermediate tables'[ID]='Table'[ID]),[Index])
    Table2Index =
    SUMX(FILTER(ALL('Intermediate tables'),'Intermediate tables'[ID2]='Table2'[ID2]),[Index])
    Table2_amount =
    SUMX(FILTER(ALL('Table2'),'Table'[Table1Index]='Table2'[Table2Index]),[Amount])
    Flag =
    IF(
       'Table'[Table2_amount]='Table'[Amount],1,0)
    Value =
    IF(
        [Flag]=1,COUNTX(FILTER(ALL('Table'),[Flag]=1),[ID]),0)

    2. Result:

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

     

    Best Regards,

    Liu Yang

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

  • No se puede realizar de alguna forma sin tener que generar una tabla nueva que tenga las dos columnas que me interese? Es decir, no existe una expresión DAX que permita comparar valores de dos tablas distintas?

    Mil gracias!!