Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Incorrect total in DAX measure

I have this DAX measure:

Var TablaCalculo = ADDCOLUMNS(
        VALUES('PartesTrabajo'[Empleado_ID]),  -- Reemplaza 'TuCampoDeReferencia' con el campo que identifica las filas en 'PartesTrabajo'
        "Horas", SUM('PartesTrabajo'[Horas]),
        "AsignadoGlobal", [asignado_global]
    )
RETURN

IF(
    SUMX(TablaCalculo, [Horas] - [AsignadoGlobal]) < 0,
    IF(
        MAXX(OrdTrabGeTr,OrdTrabGeTr[Estado]) = "Abierta",
        0,
        SUMX(TablaCalculo, [Horas] - [AsignadoGlobal])
    ),
    SUMX(TablaCalculo, [Horas] - [AsignadoGlobal])
)


The problem is that when we're in the global context, the mesure returns 0 because "Horas" is lower than "AsignadoGlobal" and I want to return the resulted total inside of the IF clause.

2 Replies

  • Anonymous ,

    Try measure like

     

    Var TablaCalculo = ADDCOLUMNS(
    VALUES('PartesTrabajo'[Empleado_ID]),
    "Horas", SUM('PartesTrabajo'[Horas]),
    "AsignadoGlobal", [asignado_global],
    "Diff", SUM('PartesTrabajo'[Horas]) - [asignado_global]
    )
    RETURN

    SUMX(TablaCalculo,
    IF(
    MAX(OrdTrabGeTr[Estado]) = "Abierta",
    [AsignadoGlobal], // Return the actual negative total
    [Diff] // Optionally, handle other cases if needed
    )
    )

    • Anonymous's avatar
      Anonymous
      Not applicable



      I think that the "MAX(OrdTrabGeTr[Estado]) = "Abierta" is going to return always only one branch.
      I need this condition to check if a Work Order (the record) is still open, and when is the total "case" I just want to forget it and take the result of this logic.

      Given this desviation:


      Is resulting in 0 because of the problem with the measure that I've described earlier.

      Expected result: 0 + 14,4 + 7 + 2,5 = 23,9