Forum Discussion

afrutos's avatar
afrutos
Resolver I
1 year ago

SUMX IGNORE SOME ROWS

Hola, en mi PowerBi tengo una tabla de Facturas unida a la tabla calendario de 1 a * a través de fechafactura.

Esta es la visual que necesito; actualmente estoy filtrando por el año actua, es decir 2024.
Estoy teniendo problemas para calcular la suma correcta de una medida.

La medida [NW FACT LY] es simplemente la suma de facturación.
la medida [AJUSTE LY...] es lo mismo pero ajustando el valor final de CL, ya que al total de CL para cada año tengo que sumar o restar un ajuste.

AJUSTE LY FACTURACIÓN FINAL =
VAR k = SELECTEDVALUE('Facturas Anexo'[TipoLiquidacion])
VAR YearTotal =
    CALCULATE(
        SUM('Facturas Anexo'[AJUSTE IMPORTE]),
        SAMEPERIODLASTYEAR('FACT_Dim_Calendar DAX'[Date])
    )

VAR adjustedValue =
    SWITCH(
        TRUE(),
        k = "CL" && SELECTEDVALUE('FACT_Dim_Calendar DAX'[#Año]) = 2018, YearTotal - 952721.8,
        k = "Op" && SELECTEDVALUE('FACT_Dim_Calendar DAX'[#Año]) = 2018, YearTotal - 622131.45,
        k = "CL" && SELECTEDVALUE('FACT_Dim_Calendar DAX'[#Año]) = 2021, YearTotal + 752152,
        k = "CL" && SELECTEDVALUE('FACT_Dim_Calendar DAX'[#Año]) = 2023, YearTotal - 1175870.95,
        k = "CL" && SELECTEDVALUE('FACT_Dim_Calendar DAX'[#Año]) = 2024, YearTotal - 885903.42,
        YearTotal
    )

RETURN
    IF(ISBLANK(adjustedValue), 0, adjustedValue)




Y lo que necesito en última instancia es sumar el valor correcto de los valores que arroja esa medida, pero me hace desaparecer la 2 y penultima línea.
SUMX LY AJUSTE FACTURACION =
SUMX(
    VALUES('Facturas Anexo'[TipoLiquidacion]),
    CALCULATE(

[AJUSTE LY FACTURACIÓN FINAL]

    )
)

Por favor, necesito ayuda, hay algo que no estoy entendiendo.

 

2 Replies

  • Hi afrutos ,

     

    Although this does not directly address your requirement, hardcoding values directly into DAX measures is not good practice. It can lead to several problems, such as a lack of flexibility, high maintenance needs, increased error-proneness, and difficulty in auditing. A better approach would be to store those adjustment values in a separate lookup table and reference them dynamically. This makes your model easier to maintain, more scalable, less prone to errors, and easier to audit.

     

    Best regards,

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi afrutos ,

     

    Could you please provide some sample data or link to the pbix file?

     

     

    Best regards,

    Mengmeng Li