Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

DAX Max value from another column based on row value

I'm trying to write a DAX function to find the maximum value in one column based on a condition in another, but have this condition change dynamically based on the row value.
 

With this code:

 

CALCULATE(MAX(RankOfArea[count]),filter(RankOfArea,RankOfArea[Line]="Pic"))

I get this table:

 

count |  Line  |  Max
7220  | Pic    |  7220
283   | Dis    |  7220
3557  | Pic    |  7220
317   | Met    |  7220
500   | Met    |  7220

And I'd like this result:

 

count |  Line  |  Max
7220  | Pic    |  7220
283   | Dis    |  283
3557  | Pic    |  7220
317   | Met    |  500
500   | Met    |  500

Of course I have to remove the ="Pic", but not sure what to replace it with? Many thanks

  • HI Anonymous

     

    Try this

     

    =
    CALCULATE (
        MAX ( RankOfArea[count] ),
        ALLEXCEPT ( Rankofarea, Rankofarea[Line] )
    )

13 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    HI Anonymous

     

    Try this

     

    =
    CALCULATE (
        MAX ( RankOfArea[count] ),
        ALLEXCEPT ( Rankofarea, Rankofarea[Line] )
    )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi  ,

       

      Thanks for your reply.

       

      Why did you change the post title please? I don't want to return a running total, rather the maximum value.

       

      Edit - sorry that worked, my typing. No idea why. Thanks.

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Community Champion

        Hi Anonymous

         

        :smileysurprised:I didn't change the post title:smileysurprised::smileysurprised:

         

         

    • JQuon's avatar
      JQuon
      Helper I

      Is it possible to use this formula and only show where the Maximum is within the given row and all other rows show blank?  I would like to return an X in the row where the max is.  I need to do this so I can filter the data through a slicer for X and ignore blanks?

       

       

      Type      Version   Max

      Apple         1

      Apple         3

      Apple         8

      Apple         9          x

      Peach         1

      Peach         10        x

      Peach         7

      Peach         4

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Community Champion

        JQuon

         

        You can use this calculated column

         

        Assuming your TableName  is Table1

         

        MAx_Column =
        IF (
            Table1[Version]
                = CALCULATE ( MAX ( Table1[Version] ), ALLEXCEPT ( Table1, Table1[Type] ) ),
            "X"
        )