Forum Discussion

jayantkodwani's avatar
jayantkodwani
Microsoft Employee
6 years ago
Solved

MAXIF CALCULATED COLUMN

I need to implement MAXIF as a calculated column. It is piece of cake in Excel as shows below but I am not able to get exact DAX formula in POWER BI.  

 

I have 3 columns and the MAXIF formula in Excel matches the ID as well as value column, the result is the max month where ID is same and value is "-1" (i.e. June for Id=101 AND May for id=201), 

 

In Power BI I have tried the below but it does not consider the ID at the row level and gives June for both the id's ( see PBI snapshot)  How can I achieve the results shown in Excel snaphsot but in PBI?

 

Max Month where ID is minus 1 = calculate(max(Test[Fiscal Month]),FILTER(Test,Test[ID]=Test[ID] && Test[Value] = -1))

 

 

 

Here is the sample Data:

 

ID Fiscal Month Value Max Month where ID =1
101 4/1/2020 1 6/1/2020
101 6/1/2020 -1 6/1/2020
201 12/1/2019 1 5/1/2020
201 2/1/2020 -1 5/1/2020
201 2/1/2020 1 5/1/2020
201 5/1/2020 -1 5/1/2020

  • v-xuding-msft's avatar
    v-xuding-msft
    6 years ago

    Hello @jayantkodwani ,

    You can add an ALLEXCEPT() as shown below:

    Column =
    CALCULATE (
        MAX ( 'Table'[Fiscal Month] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Value] = -1 )
    )
    

  • FrankAT's avatar
    FrankAT
    6 years ago

    Hello @v-xuding-msft

    here's my solution (see figure)

    24-08-_2020_14-15-58.png

    Max Month where ID is minus 1 = 
    CALCULATE(
        MAX('Table'[Fiscal Month]),
        FILTER(
            ALLEXCEPT(
                'Table',
                'Table'[ID]
            ),
            'Table'[Value] = -1
        )
    )

    Greetings FrankAT

5 Replies