Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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 have so far:
Average_Max_Day =
AVERAGEX (
GROUPBY (
test_table,
test_table[ID],
"max_value", MAXX ( CURRENTGROUP (), test_table[Value] )
),
[max_value]
)
For those familiar with python, I can achieve the desired results with this code:
import pandas as pd
df = pd.read_excel("test.xlsx",usecols=['ID','Date','Value'])
df_grouped = df.loc[df.groupby(['ID'])['Date'].idxmax()]
df_average = df['Value'].mean()
Solved! Go to Solution.
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
)
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Hi @klintala
I am trying to accomplish this "group by" below from my Python code. I am trying to get the median of each of them.
the group by on power Bi is not working, can you please advice?
Many thanks for considering my request.
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
)
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
That did the trick. Thank you very much. How have I never realized we can write variables inside functions?
I'm still not entirely sure how this works, but I was able to play around with it to see how I can get different results.
@klintala Awesome - so glad it worked. Variables inside functions is an advanced DAX concept and a great way to manipulate the evaluation context of the variable. You've just opened up a whole new world. 🙂
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com