Search code examples
powerbidaxpowerbi-desktopmeasure

Calculate + IF in DAX for Power BI


I have a table (PIB) with 3 fields: Name, Filter and Value I have this Measure to deploy Data, and it works:

 Data = CALCULATE(
                SUM('PIB'[Value]),    
                'PIB'[Filter] IN { "Dato base" }
                )

I want to add an IF (or something similar) to multiply Value by -1 when column Name equals to "Companies". I have tried this, and doesn`t work:

Data = CALCULATE(
                IF('PIB'[Name]=Companies; SUM('PIB'[Value])*-1;SUM('PIB'[Value])),    
                'PIB'[Filter] IN { " Dato base" }
                )

Anybody knows how can I do it? This way or any other Thank you!


Solution

  • Data = 
    VAR x = 
    CALCULATE(
            SUM('PIB'[Value]),    
            'PIB'[Filter] IN { "Dato base" }
            )
    RETURN 
    IF(MAX(PIB[Name]) = "Companies", x*-1, x)