March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I have a table of cash receipts with a date column (i.e., 1/1/2022...4/4/2022). I'd like to calculate the average amount received by week day. So if there were 3 Mondays in the date range and the total collected on those Mondays was $3,000,000, I'd expect to see an output like this:
Weekday | Average
---------------------
Mon $1,000,000
Solved! Go to Solution.
Hi @mcmullenrich
Sorry for the late reply. Here is the workable solution as per sample sample
Average of Amt :=
DIVIDE (
SUM ( Combined[Amount] ),
COUNTROWS ( FILTER ( 'Calendar', NOT ISBLANK ( Combined[Sum of Amt] ) ) )
)
you can create a new calculated column for weekday
FORMAT ( WEEKDAY(Table[Date]), "dddd" )
then use it in your visual with simple AVERAGE Measure
Thanks @tamerj1. I tried this and got the average of all the individual transaction instead of the average daily total for each day.
Try
DIVIDE (SUM (Table[Value]), CALCULATE (SUM(Table[Value]), ALLSELECTED(Table[Weekday])))
Hmm...that got me a 1 for each day. I think I'm using the wrong Table[Value] on one of them:
Average per Weekday :=
DIVIDE (
SUM ( Combined[Amount] ),
CALCULATE ( SUM ( Combined[Amount] ), ALLSELECTED ( 'Calendar'[Day Of Week] ) ),
0
)
I believe I misunderstood your reqyirement. You just want to divide over the number of frequency of the selected weeday. Therefore if you are using a date table just do:
Average per Weekday :=
DIVIDE (
SUM ( Combined[Amount] ),
COUNTROWS ( 'Calendar' )
)
I'm going to try this when I get home. That said, to ensure I understand it and you understand what I'm looking to do, here is how I would solve it in excel:
Start with a table having columns "Date" and "Amount"
Add a column called "Weekday" with formula =WEEKDAY(Date)
Off to the right, create a small table with numbers 1 through 7 as rows
Create columns Total (=SUMIF(Weekday, Day, Amount) and Count (=COUNTIF(Weekday, Day)
Divide Total by Count
This would give me the total deposits on each weekday and divide it by the number of occurrences of each workday for an average daily total for each weekday.
That is clear enough. But in Power Bi you have a date table with the weekday name column and this table is connected with the fact table through the date column. Is that correct?
Yes, that's correct
Then I hope the last solution works.
Not quite there yet. I realized the issue, just not sure how to solve in DAX. My excel-based approach above only works if I have a single entry for each date (i.e., a daily deposit amount). However, in my PBI table, I have multiple transactions for each date. As such, your approach gives me much smaller numbers than it should be. I need to find a way to sum by date before adding and counting.
@mcmullenrich
Even though, COUNTROWS ( 'Calendar' ) should give the frequency count of the selected weekday as the date table has no duplicates. Can you please share some screenshots of you tabels, data model, report and the measure?
This feels a bit like I cheated, but it did get me the result that I wanted:
Average per Weekday :=
DIVIDE ( [Sum of Amt], MAX ( Combined[WeekNo] ) - MIN ( Combined[WeekNo] ) + 1 )
Hi @mcmullenrich
Sorry for the late reply. Here is the workable solution as per sample sample
Average of Amt :=
DIVIDE (
SUM ( Combined[Amount] ),
COUNTROWS ( FILTER ( 'Calendar', NOT ISBLANK ( Combined[Sum of Amt] ) ) )
)
Hi @mcmullenrich ,
I'd suggest to create a date dimension in Power BI where one of the attributes is weekday. Here you have a blog post where they explain how to create such a date dimension.
Power Bi for Beginners: How to create a Date Table in Power Bi - Softcrylic
Afterwards, create an Average measure and drag in the WeekDay attribute into your visual.
Let me know if this helps or if yiou have any other questions 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! |
#proudtobeasuperuser |
Thanks @tackytechtom. So I'm actually working in PowerPivot, not PowerBI. I figured the DAX would be the same, but maybe not. I created a date table and have established the relationship between my transaction table and it. However, the closest I have come to getting the right output is to get the total deposits by weekday divided by the 7 days in the week instead of the 14 distinct occurences of each weekday.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
User | Count |
---|---|
26 | |
16 | |
15 | |
12 | |
11 |
User | Count |
---|---|
35 | |
26 | |
26 | |
20 | |
15 |