Forum Discussion

klintala's avatar
klintala
Frequent Visitor
4 years ago
Solved

Groupby and return values based on another column

I want to return the Value at the max Date for each ID. (then avergage those values)   I am able to return the max Value for each ID, but not the value at the max Date of each ID. Here is what I h...
  • AllisonKennedy's avatar
    4 years ago

    klintala 

     

    You can use a variable to store the Max date, then find the value for that date: 

     

    Average_Max_Day = 
    AVERAGEX( Values( test_table[ID]) ,
       VAR _ID = test_table[ID]
       VAR _MaxDay = MAXX(FILTER(test_table, test_table[ID] = _ID), test_table[Date] )
       RETURN
       SUM( test_table[Value] ) --change this to average or max depending on how you want to aggregate the value per day per ID
        )