DAX - Calculate Average Of Max Day Transactions For Week

dlrosencrans

New Member
Joined
Apr 27, 2017
Messages
4
Hoping someone has a number of ideas or a solution.

The requirement I have is to calculate a weekly average from a daily max transaction calculation for each day.
The following measures are working:
MaxTrans:=MAX(TransactionTable[Transactions])
MaxTransOnDay:=MAXX(VALUES(DimDate[Date]),[MaxTrans])
MaxTransOnCurrentWeek:=CALCULATE([MaxTrans],FILTER(All(DimDate), DimDate[WeekOfYearNumber] = MIN(DimDate[WeekOfYearNumber])))

A sample of the transaction table looks like:
UserDateTimeTransactions
G14/25/2017 9:00:00 AM30
G24/25/2017 9:00:00 AM45
G14/25/2017 9:15:00 AM40
G14/25/2017 10:00:00 AM33
G24/26/2017 9:00:00 AM39
G14/26/2017 11:00:00 AM18

<tbody>
</tbody>

The Pivot looks like: Filtering User, Week, and Day (M-F)
UserDateMaxTransOnDayMaxTransOnWeek
G14/25/20174040
G14/26/20171840

<tbody>
</tbody>

What I am struggling with is the MaxAvgWeek:
UserDateMaxTransOnDayMaxTransOnWeekMaxAvgWeek
G14/25/2017404029
G14/26/2017184029

<tbody>
</tbody>

[FONT=&quot]MAxAvgWeek:=CALCULATE(AVERAGEX(Transactions,[MaxTransDay]),FIL[/FONT]<wbr style="box-sizing: inherit; color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: medium;">[FONT=&quot]TER(ALL(Transactions),Transactions[WeekNum]=MAX(D[/FONT]<wbr style="box-sizing: inherit; color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: medium;">[FONT=&quot]ate[WeekNum])))[/FONT]

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I don't think I understand some of what you have done with your existing measures. Do MaxTrans and MaxTransOnDay return different values?

Anyway, if I understand correctly what you are trying to do, ie report the average daily maximum for the week that you are looking at. If so you want to iterate over the column that lists the days.

MAxAvgWeek:=CALCULATE(AVERAGEX(VALUES(Date[Days]),[MaxTransDay]),FIL<wbr style="background-color: rgb(250, 250, 250); box-sizing: inherit; color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: medium;">TER(ALL(Transactions),Transactions[WeekNum]=MAX(D<wbr style="background-color: rgb(250, 250, 250); box-sizing: inherit; color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: medium;">ate[WeekNum])))
 
Upvote 0
Thanks for the response. Has helped, but I have a feeling my filter contexts are off. Back to training/review.

Here is what I am ultimately after:

Pivot Table:
LocationWeekNumDateMaxDayAvgCurrentWeekAvgPrevWeek
Cust1154/3/20173339
Cust1154/6/20174539
Cust1164/10/2017222239
Cust69164/11/20175050
Rover164/10/20176973
Rover164/11/20177773

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>

Power BI Table with filters/measures:
LocationWeekNumMaxDayMAxAvgWeek
Cust1154539
Cust1162273
Cust691539
Cust69165073
Rover1539
Rover167773

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

Cust1 weeknum 16 avg should be 22
Cust69 should not have an avg for week 15 no data, and week 16 avg should be 50 not 73
Rover avg for week 16 is correct, but should have no data for week 15.

Table = SUMMARIZE('Transaction','Transaction'[Location],'Transaction'[MonthNumber],'Transaction'[Date],'Transaction'[WeekNum],"MaxPerDay",MAX('Transaction'[Transactions]))
MaxDay = MAX('Table'[MaxPerDay])
MAxAvgWeek = CALCULATE(AVERAGEX(VALUES('Date'[Weekday]),[MaxDay]),FILTER(ALL('Table'),'Table'[WeekNum]=MAX('Date'[WeekNum])))

Thanks!
Doug
 
Upvote 0
Sorry, if I didn't help. Not sure I was / am 100% understanding.

Looking again at the formula, why is are using WeekNum from two different tables? What happens if you take both from the Date table?
 
Upvote 0
I have a Date table that is joined to the Table. Date is then filtered by year, month, and then date. WeekNum is in both tables. Based on the date selected in the filter among other filters, I then am attempting to apply the measure against those filters.

Seems there is an error when I try to replace Table[WeekNum] with Date[WeekNum], because this is not a single value.

I'm missing something and will consult more documentation/samples.

Thanks,
Doug
 
Upvote 0
Actually, I can see a problem in the code. You are removing the filtering on 'Table' by calling it with ALL(). Maybe try something like this.

MAxAvgWeek = CALCULATE(AVERAGEX(VALUES('Date'[Weekday]),[MaxDay]),FILTER(ALL('Date'),'Date'[WeekNum]=MAX('Date'[WeekNum])))

Or otherwise maybe use All('Table'[WeekNum]) so you are only removing the filtering from that column.
 
Upvote 0
Thanks for the additional assist.

I am going to go back and review filter contexts as this appears to be the root of my confusion.

Doug
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,928
Members
449,274
Latest member
mrcsbenson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top