Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Petr__
Helper II
Helper II

Group by + avg

Hello guys,

I need to help with following group by and average dax formula

 

my data

 

y_m              value
2022_1              1
2022_1              2
2022_1              3
2022_2              4
2022_2              5
2022_2              6
2022_3              7
2022_3              8
2022_3              9

 

and I would like to get

 

y_m              value
2022_1              2
2022_2              5
2022_3              8

 

I tried to this dax formula

measure = GROUPBY(Date_Dim,Date_Dim[y_m],"result",AVERAGEX(CURRENTGROUP(),fact[abs(value)]))
 
but receive an error:
The CALCULATE formula cannot be used in expression argument for the GROUPBY() function

any idea ? how to do it ?
1 ACCEPTED SOLUTION

@Petr__ Measures cannot return tables. Your original formula works for me to create a table:

Table 2 = GROUPBY('Table','Table'[y_m],"result",AVERAGEX(CURRENTGROUP(),'Table'[value]))

Also, it works in a measure to create a table var:

Measure = 
    VAR __Table = GROUPBY('Table','Table'[y_m],"result",AVERAGEX(CURRENTGROUP(),'Table'[value]))
    VAR __y_m = MAX('Table'[y_m])
RETURN
    MAXX(FILTER(__Table,[y_m] = __y_m),[result])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Petr__ Just use measure = AVERAGE('Table'[value])


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler 

but I need that output will be table not one value

@Petr__ Measures cannot return tables. Your original formula works for me to create a table:

Table 2 = GROUPBY('Table','Table'[y_m],"result",AVERAGEX(CURRENTGROUP(),'Table'[value]))

Also, it works in a measure to create a table var:

Measure = 
    VAR __Table = GROUPBY('Table','Table'[y_m],"result",AVERAGEX(CURRENTGROUP(),'Table'[value]))
    VAR __y_m = MAX('Table'[y_m])
RETURN
    MAXX(FILTER(__Table,[y_m] = __y_m),[result])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors