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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
yukon
Helper I
Helper I

average by group

Hello,

 

I'm start learning DAX. I'm using DAX to get below figure. But i have difficult to get correct figure. What i want to do is "Average Plan Sales Amout by Group (Year)".

 

Except result

 

Year      CountryPlan Sales AmountAvg Amt.
2019AU1918365911019810
2019ID63095269999328.875
2019IN967421710526443.57
2019JP741382610668481.33
2019KR2167148811319412.4
2019MY80652778731393.5
2019SG125168778953432.333
2019TH71038307171710
2019TW72395907239590
2020AU10005000
2020ID20005500
2020IN30006000
2020JP40006500
2020KR50007000
2020MY60007500
2020SG70008000
2020TH80008500
2020TW90009000

 

 

Here is my DAX formula in Excel Data Model. I'm using Dax in excel data model.

 

Untitled.png

 

Many thanks for your help.

3 ACCEPTED SOLUTIONS
littlemojopuppy
Community Champion
Community Champion

Hola!

 

Try this...

 

=AVERAGEX(
	FILTER(
		Table1,
		Table1[Year] = EARLIER(Table1[Year])
	),
	Table1[Plan Sales Amount]
)

 

 

Capture.PNG

 

Capture2.PNG

View solution in original post

az38
Community Champion
Community Champion

@yukon 

is it some running average? it looks like you have an error in Excel

if you need average from all groups by year try a measure

Average Plan Sales Amout by Group (Year) =
CALCULATE(AVERAGE(Table[Plan Sales Amount]), ALLEXCEPT(Table, Table[Year]) )

or column from @littlemojopuppy  solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

Anonymous
Not applicable

@yukon 

Average by group can be done in ways in DAX, like this above answers. However, I think the data you provided is not correct for some reason. How can you get different values when you average. Maybe check your excel files and also provide the formula you used so we can see what are you calculating to get that expected result.

 

Usually, you get average by group(year) with column or measures using:

RESULT = CALCULATE(AVERAGE([Plan Sales Amount]), ALLEXCEPT(Table,[Year]))


Best regards
Paul Zheng

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

@yukon 

Average by group can be done in ways in DAX, like this above answers. However, I think the data you provided is not correct for some reason. How can you get different values when you average. Maybe check your excel files and also provide the formula you used so we can see what are you calculating to get that expected result.

 

Usually, you get average by group(year) with column or measures using:

RESULT = CALCULATE(AVERAGE([Plan Sales Amount]), ALLEXCEPT(Table,[Year]))


Best regards
Paul Zheng

@az38 ; @littlemojopuppy ; @amitchandak ; @Anonymous 

 

You all provide the AVG formula is corrrect. Excel file formula is wrong after i checked with the person who give me the file.

 

Thank you so much for sharing the formula. I have learn a lot from you all.

 

littlemojopuppy
Community Champion
Community Champion

Hola!

 

Try this...

 

=AVERAGEX(
	FILTER(
		Table1,
		Table1[Year] = EARLIER(Table1[Year])
	),
	Table1[Plan Sales Amount]
)

 

 

Capture.PNG

 

Capture2.PNG

The difference between what I posted is that @az38 created a measure and I created a calculated column (which is what you seemed to want).  His will work if you want a measure, and I've shown mine works as a column.

@littlemojopuppy ,

 

Thank for your formula. What i'm trying to get below result

 

22-3-2020 10-58-13 PM.png

so sorry for my poor explanation

Your average formula...what is it averaging?

@littlemojopuppy 

 

This is excel formula that i got from existing excel file and trying to convert as data model.

 

Year 2019

22-3-2020 11-06-58 PM.png

Year 2020

22-3-2020 11-10-06 PM.png

 

Many thanks

@yukon ,

 

Try like

calculate(average(table[plan sales amout]),filter(all(table), table[year]= max(table[year]) && table[country code]= max(table[country code])))
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

@yukon 

is it some running average? it looks like you have an error in Excel

if you need average from all groups by year try a measure

Average Plan Sales Amout by Group (Year) =
CALCULATE(AVERAGE(Table[Plan Sales Amount]), ALLEXCEPT(Table, Table[Year]) )

or column from @littlemojopuppy  solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

It's not a running average and it's doesn't seem to be an average through the rest of the group.  Can you share the formula that isn't the first one?  That might help figure out what it is.

 

az38
Community Champion
Community Champion

Hi @yukon 

try ALLEXCEPT

Average Plan Sales Amout by Group (Year) =
CALCULATE(AVERAGE(Table[Plan Sales Amount]), ALLEXCEPT(Table, Table[Year], Table[Country]) )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.