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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
EMassicot
Frequent Visitor

DAX formula for averages

I have a table with the columns "ID" ,"month" , "score" and "publish date". I want to first create a measure that gets me the "average score per publish date" and then use the values from the measure to get the average score per month.

 

Here's a table as an example

IDScorePublish Date
1909/14/2022
1609/14/2022
1759/15/2022
1859/15/2022

 

 

What I want but do not know how to do.

 

Step 1. Averge score per publish date 9/14/2022

90+60 = 150/2= 75

Step 2. Average score per publish date 9/15/2022

85+75= 160/2 = 80

Step 3. Average score per month. ( using average score per publish date to calculate)

80+75= 155/2 = 77.5

 

What I know how to do but do not want.

Step 1. Average score per month( using scores to caluclate)

90+60+85+75 = 77.5

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

The below measure should work across any date range - week, month, quarter etc

Avg Score =
AVERAGEX (
    ADDCOLUMNS (
        VALUES ( 'Date'[Date] ),
        "@val", CALCULATE ( AVERAGE ( 'Table'[Score] ) )
    ),
    [@val]
)

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @EMassicot ;

You could create measures as follow:

1.

average score per publish date = CALCULATE( AVERAGE('Table'[Score]),ALLEXCEPT('Table','Table'[Publish Date]))

2.

average score per month = AVERAGEX(SUMMARIZE(ALL('Table'),[Publish Date],"1",[average score per publish date]),[1])
average score per month2 = CALCULATE(AVERAGE('Table'[Score]),FILTER(ALL('Table'),EOMONTH([Publish Date],0)=EOMONTH(MAX('Table'[Publish Date]),0)))

The final show:

vyalanwumsft_0-1663553159483.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
EMassicot
Frequent Visitor

I have a table with the columns "ID" ,"month" , "score" and "publish date". 

 

What I ultimately want, is to get the avearge score per each publish date using a DAX  formula.

 

Here's a table as an example

IDScorePublish DateMonth
1909/14/2022September
1609/14/2022September
1759/15/2022September
1859/15/2022September

 

 

What I want but do not know how to do.

 

Step 1. Averge score per publish date 9/14/2022

90+60 = 150/2= 75

Step 2. Average score per publish date 9/15/2022

85+75= 160/2 = 80

 

Here is also the DAX formula that I tried using but it's not giving me exactly what I want.

 

Average Score Per Publish Date =
CALCULATE(
AVERAGE ( 'Table'[Score] ),GROUPBY('Table','Table'[Publish Date]'Table '[ID]),

@EMassicot Put Publish Date in a table visual. Use a simple Average aggregation on Score.


@ 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...
v-yalanwu-msft
Community Support
Community Support

Hi, @EMassicot ;

You could create measures as follow:

1.

average score per publish date = CALCULATE( AVERAGE('Table'[Score]),ALLEXCEPT('Table','Table'[Publish Date]))

2.

average score per month = AVERAGEX(SUMMARIZE(ALL('Table'),[Publish Date],"1",[average score per publish date]),[1])
average score per month2 = CALCULATE(AVERAGE('Table'[Score]),FILTER(ALL('Table'),EOMONTH([Publish Date],0)=EOMONTH(MAX('Table'[Publish Date]),0)))

The final show:

vyalanwumsft_0-1663553159483.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

johnt75
Super User
Super User

The below measure should work across any date range - week, month, quarter etc

Avg Score =
AVERAGEX (
    ADDCOLUMNS (
        VALUES ( 'Date'[Date] ),
        "@val", CALCULATE ( AVERAGE ( 'Table'[Score] ) )
    ),
    [@val]
)

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.