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
Anonymous
Not applicable

Average based on time values

I have 2 tables... One that holds my sales stats per day.  And another table that I'm using that has all my Date/Week/Month columns and created a realtionship between my Sales table and my Calendar table based on the Date column in my Sales table and the Date column in my Calendar table.

 

I'm now trying create a DAX that will give me an average sales, based on a slicer of "weeks" (and I'm choosing 3 weeks), and grouping the sales by Day of Week (Sun, Mon, Tue, Wed, Th, Fri, Sat).

 

When I use the Clustered Column Chart, it automatically sums the sales per weekday, and does not allow me to do or chose an "average" as a choice.

 

Jazzyfey11_0-1598582492079.png

Any ideas?

7 REPLIES 7
amitchandak
Super User
Super User

@Anonymous , if you have created as the measure then it will not give an option to change the aggregation

 

sales measure = sum(sales[sales])

if it giving/showing sum then it should give an average. If it is not showing both means data type is not number, change it.

 

If sorting is an issue. you should use a sort column.

https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column

Anonymous
Not applicable

Thanks.  You're absolutely right, looking at the sales, I did have it set as a measure based on the original data table I am calculating to. 

 

AllSales = Calculate(sum(SalesData[TotalSalesValue]),SalesData[ProductSalesName)="Sales")

 

And I think that's where I'm stuck.  Because it is a measure.

 

When using that measure inside the graph, grouping it by WeekDay, and a slicer that is choosing how many weeks to calculate, that's where I'm stuck in trying get an average for each weekday, instead of a total for each weekday.

Does this expression give your expected result?  It should do same filter on ProductSalesName but average instead of Sum.

 

AllSales = Calculate(Average(SalesData[TotalSalesValue]),SalesData[ProductSalesName)="Sales")

 

Or, if you want average per week you can reference the measure above in

Avg Weekly Sales = AVERAGEX(VALUES('Calendar'[Week'), [AllSales])

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks mahoneypat,

So I did try the

 

AllSales = Calculate(Average(SalesData[TotalSalesValue]),SalesData[ProductSalesName)="Sales")

 

And based on how the SalesData table is laid out, at a transactional level (each day, each salesperson,productsales name, and salesvalue), it is averaging the sales, but it looks like per sales person, instead of the total sales for that day..

 

So the total sales per each Sunday was:

Sunday 1 = 4143

Sunday 2 = 2861

Sunday 3 = 3390

 

The average for those 3 sundays should be: 3464

 

Doing the DAX above, it's giving me 17, which is more the average per sales agent, instead of the total for Sunday..

 

 

Hi @Anonymous ,

Not certain what did 17 represent under this measure. Could you consider sharing some sample data or sample file for further discussion? It would let us help you better to solve this issue.

 

Best Regards,
Yingjie Li

@Anonymous This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.


@ 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...
Anonymous
Not applicable

So, Greg_Deckler,

Using this layout for AverageX

AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])

 

Could it then look something like this:

 

SalesAverage =
Var Sales = Calculate(sum(SalesData[TotalSalesValue]),SalesData[ProductSalesName)="Sales")

RETURN

AverageX(summarize(SalesData,SalesData[ProductSalesName],"SalesAve",Sales),[SalesAve])
 
The Var Sales was the original DAX I used to get the sum of the Sales Value looking up the column data of Product Sales Name that had "Sales" in the row.
 
Using this, which feels like it's in the right vein of your method, it still sums up the total sales.
 
I know I'm missing something.

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.