Forum Discussion

tonymaclaren's avatar
tonymaclaren
Helper I
8 years ago
Solved

highest value by category

Hi

I am strugling with a problem as follows:

I need a DAX measure to find the percentage that matches the highest year value for a given category. So Category A would equal 9 % and Category B would be 70%. Year is not a date value, it is a whole number field.

 

CategoryPercentageYear
Category A24%2012
Category A45%2013
Category A32%2014
Category A56%2015
Category A9%2016
Category B45%2012
Category B46%2013
Category B89%2014
Category B32%2015
Category B70%2016

 

Thanks in advance.

Tony

  • tonymaclaren

     

    As a MEASURE.....

     

    Max Percentage measure =
    VAR MaxYear =
        CALCULATE (
            MAX ( 'User Table'[Year] ),
            ALLEXCEPT ( 'User Table', 'User Table'[Category] )
        )
    RETURN
        CALCULATE (
            MAX ( 'User Table'[Percentage] ),
            FILTER (
                ALLEXCEPT ( 'User Table', 'User Table'[Category] ),
                'User Table'[Year] = MaxYear
            )
        )

     

     

6 Replies

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi tonymaclaren,

     

    Max Percentage =
    CALCULATE (
        MAX ( 'User Table'[Percentage] ),
        FILTER (
            ALLEXCEPT ( 'User Table', 'User Table'[Category] ),
            'User Table'[Year] = MAX ( 'User Table'[Year] )
        )
    )

     

    Best regards,

    Yuliana Gu

    • tonymaclaren's avatar
      tonymaclaren
      Helper I

      Thank you Yuliana,

      You have provided a column formula. Is it possible to use a measure instead ?

      Tony

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Community Champion

        tonymaclaren

         

        As a MEASURE.....

         

        Max Percentage measure =
        VAR MaxYear =
            CALCULATE (
                MAX ( 'User Table'[Year] ),
                ALLEXCEPT ( 'User Table', 'User Table'[Category] )
            )
        RETURN
            CALCULATE (
                MAX ( 'User Table'[Percentage] ),
                FILTER (
                    ALLEXCEPT ( 'User Table', 'User Table'[Category] ),
                    'User Table'[Year] = MaxYear
                )
            )

         

         

  • drewlewis15's avatar
    drewlewis15
    Solution Specialist

    Max Percentage = CALCULATE(MAX('Table'[Percentage]), FILTER('Table', 'Table'[Year] = MAX('Table'[Year])))

    • tonymaclaren's avatar
      tonymaclaren
      Helper I

      Unfortunately that does not work, it merely duplicates the percentage column.

      Max Percentage test =
      CALCULATE (
          MAX ( 'Table'[Percentage] ),
          FILTER ( 'Table', 'Table'[Year] = MAX ( 'Table'[Year] ) )
      )

      CategoryPercentageYear Max Percentage
      Category A24%201224%
      Category A45%201345%
      Category A32%201432%
      Category A56%201556%
      Category A9%20169%
      Category B45%201245%
      Category B46%201346%
      Category B89%201489%
      Category B32%201532%
      Category B70%201670%