Question: I have a big model in PowerBI where there are many different aggregation and grouping based on columns being displayed or not on the final table.

Simplifying: I need to do a conditional statement doing the **sum if the value of column 1 is A1 but doing the MAX() if the value of column 1 is A2.**

[![enter image description here](https://i.stack.imgur.com/AOQxV.png)](https://i.stack.imgur.com/AOQxV.png)

I need to have that information in the same column of the final output.

How would you go for this one?

Thank you very much for your help!

Answer: 
if you have only two values you can do a simple IF like this :

```
Measure = IF ( SELECTEDVALUE('Table'[Column1]) = "A1", SUM('Table'[Column2]), MAX('Table'[Column2]))

```

[![FinalProduct](https://i.stack.imgur.com/K5Nah.png)](https://i.stack.imgur.com/K5Nah.png)
Please try this code:

```
TblMeasure =
VAR TblSummary =
    ADDCOLUMNS (
        VALUES ( FactTable[Column1] ),
        "Test",
            IF (
                FactTable[Column1] = "A1",
                SUM ( FactTable[Column2] ),
                MAX ( FactTable[Column2] )
            )
    )
RETURN
    SUMX ( TblSummary, [Test] )

```

If we test it on a table visual:

[![TblVisual](https://i.stack.imgur.com/zzV2w.png)](https://i.stack.imgur.com/zzV2w.png)