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
skaratela
Frequent Visitor

DAX - calculating weekly average over all present weeks

Hi all,

 

I want to calculate a weekly average and have tried many tutorials online and have had no joy so far...  So the issue is with the filter context (i believe) as I want to show the totals for a week and next to the total I want to show the weekly average.

 

So here is my raw data:

PBI1.jpg

 

So what I want to calculate is the weekly average, but first I aggregate by week:

 

PBI2.jpg

 

And then I add in the average for the weeks I have (it will be more than 5 in the real example), but for this problem its (3 + 3 + 1 + 2 + 1) / 5 = 1.8 :

 

PBI3.jpg

 

The problem is I cannot set the 1.8 average to display (as I have in the table above).  Here is my code so far:

 

TotalWklyAvg:=calculate(SUMX(all(vw_ActivityTable),([TotalCountMeasure])) ) / DISTINCTCOUNT(time[Week])

The TotalCountMeasure is the sum of my counts

The time[week] is the weeks

 

Your help would be most appreciated!

 

Regards,

 

S

 

 

 

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @skaratela,

 

Please modify your formula as :

TotalWklyAvg:=calculate(SUMX(all(vw_ActivityTable),([TotalCountMeasure])) ) / CALCULATE(DISTINCTCOUNT(time[Week]),ALL(time))

 

Best regards,
Yuliana Gu 

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

Hi @v-yulgu-msft

 

Sorry for the late reply.  I actuallt solved this problem by creating calculated tables.  So the first calculated table worked out the weekly total and then the second calculated table worked out the average of the weeks.  I then joined this back to my main table.

 

When I re-visit this project I will try and see if your solution works! 🙂

 

Thanks for your reply.

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.