Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Comparing previous year and current

Hello,   My goal is to compare the cost of different non qualities between the past year and the current year.   I used the following logic : Coste_LY = CALCULATE(     SUM(Tabla_CNQ_NCR[Coste_...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    Please update the formula of measure [Coste_LY] as below and also put the field [CNQ_Año] onto your table visual.

    Coste_LY =
    VAR _selyear =
        SELECTEDVALUE ( Tabla_CNQ_NCR[CNQ_Año] )
    VAR _seltype =
        SELECTEDVALUE ( Tabla_CNQ_NCR[TIPOF] )
    VAR _preyear =
        CALCULATE (
            MAX ( Tabla_CNQ_NCR[CNQ_Año] ),
            FILTER (
                ALLSELECTED ( Tabla_CNQ_NCR ),
                Tabla_CNQ_NCR[TIPOF] = _seltype
                    && Tabla_CNQ_NCR[CNQ_Año] < _selyear
            )
        )
    RETURN
        CALCULATE (
            SUM ( Tabla_CNQ_NCR[Coste_CNQ_Total] ),
            FILTER (
                ALLSELECTED ( Tabla_CNQ_NCR ),
                Tabla_CNQ_NCR[TIPOF] = _seltype
                    && Tabla_CNQ_NCR[CNQ_Año] = _preyear
            )
        )

    If the above one can't help you get the expected result, please provide some raw data in your table 'Tabla_CNQ_NCR' (exclude sensitive data) with Text format, your table visual settings and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards