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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
powerbi2srm
Resolver II
Resolver II

Calcular datos que cumplan con dos condiciones

Hola!

Os hago una breve explicación. Tengo tres tablas: una de albaranes (fact_stock_picking), una de líneas de albarán (fact_stock_move) y otra de estado de las albaranes y sus líneas (dim_picking_status), todas ellas relacionadas por su ID.

 

Los estados de albarán y de las líneas de albarán pueden ser realizado (1), abierto (2) o cancelado (3). (Los números hacen referencia a la ID).

 

Quiero el número de datos que cumplan con las siguientes dos condiciones a la vez:

  1.  Que el estado de albarán sea "realizado" (dim_picking_status[picking_status_id]=1).
  2.  Cumpliendo con la condición 1, calcular cuántas líneas de albarán tienen otro estado distitno a "realizado": dim_picking_status [picking_status_id] in 2,3.

Esto es lo que he intentado; sin embargo, en la segunda variable, no me reconoce la primera condición del IF y solo estaría calculando la segunda parte. Por tanto solo obtengo los datos que cumplen con la condición 2.

 

 

 

albaranes_realizado_con_lineas_otro = 

VAR albaranes_realizado = 
CALCULATE(
    DISTINCTCOUNT(fact_stock_picking[stock_picking_id]),
    dim_picking_status[picking_status_id] = 1,
    fact_stock_move[picking_date_id]>=20220501
    )
VAR albaranes_realizado_con_lineas_en_otro_estado =
IF(albaranes_realizado,
    CALCULATE(
        DISTINCTCOUNT(fact_stock_move[stock_move_id]),
        dim_picking_status[picking_status_id] in {2,3},
        fact_stock_move[picking_date_id]>=20220501
    )
)

RETURN albaranes_realizado_con_lineas_en_otro_estado

 

 

 

 

Muchas gracias!

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Prueba con la siguiente medida:

albaranes_realizado_con_lineas_otro =
VAR _S1 =
    CALCULATETABLE (
        VALUES ( 'fStock move'[stock_picking_id] ),
        FILTER ( ALL ( 'fStock move' ), 'fStock move'[picking_status] = 1 )
    )
VAR _SOthers =
    CALCULATETABLE (
        VALUES ( 'fStock move'[stock_picking_id] ),
        FILTER ( ALL ( 'fStock move' ), 'fStock move'[picking_status] <> 1 )
    )
VAR _Cross =
    INTERSECT ( _SOthers, _S1 )
VAR _Other =
    COUNTROWS ( FILTER ( 'fStock move', 'fStock move'[picking_status] <> 1 ) )
RETURN
    IF ( AND ( MAX ( 'fStock move'[stock_picking_id] ) IN _Cross, _Other = 1 ), 1 )

result.png

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

3 REPLIES 3
PaulDBrown
Community Champion
Community Champion

Prueba con la siguiente medida:

albaranes_realizado_con_lineas_otro =
VAR _S1 =
    CALCULATETABLE (
        VALUES ( 'fStock move'[stock_picking_id] ),
        FILTER ( ALL ( 'fStock move' ), 'fStock move'[picking_status] = 1 )
    )
VAR _SOthers =
    CALCULATETABLE (
        VALUES ( 'fStock move'[stock_picking_id] ),
        FILTER ( ALL ( 'fStock move' ), 'fStock move'[picking_status] <> 1 )
    )
VAR _Cross =
    INTERSECT ( _SOthers, _S1 )
VAR _Other =
    COUNTROWS ( FILTER ( 'fStock move', 'fStock move'[picking_status] <> 1 ) )
RETURN
    IF ( AND ( MAX ( 'fStock move'[stock_picking_id] ) IN _Cross, _Other = 1 ), 1 )

result.png

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






PaulDBrown
Community Champion
Community Champion

En la segunda VAR, pon IF(albaranes_realizado =1,......

 

Sino funciona, puedes por favor compartir una muestra de datos de las 3 tablas (que no contengan información confidencial) o un enlace a un archivo PBIX (no confidencial)?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Aquí tienes un ejemplo: 

 

Tabla 1: fact_stock_picking

stock_picking_idpicking_status_id
1011
1021
1031
1041
1051

 

Tabla 2: fact_stock_move

stock_move_idstock_picking_idpicking_status
10211011
10221011
10231012
10241021
10251023

 

Tabla 3: dim_picking_status

picking_status_idpicking_status
1Done
2Open
3Cancel

 

Quiero, por tanto, una fórmula que hiciese un recuento que cumpliera con las dos condiciones enunciadas. En este ejemplo, serían stock_picking_id = 101 y stock_picking_id = 102, puesto que tienen líneas de albarán (stock_move_id) en otro estado: 1023 y 1025.

 

Muchas gracias!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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