Forum Discussion
Average $ per weekday
- 4 years ago
Hi mcmullenrich
Sorry for the late reply. Here is the workable solution as per sample sampleAverage of Amt := DIVIDE ( SUM ( Combined[Amount] ), COUNTROWS ( FILTER ( 'Calendar', NOT ISBLANK ( Combined[Sum of Amt] ) ) ) )
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?
- mcmullenrich4 years agoFrequent Visitor
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.
- tamerj14 years ago
Community Champion
Hi mcmullenrich
Sorry for the late reply. Here is the workable solution as per sample sampleAverage of Amt := DIVIDE ( SUM ( Combined[Amount] ), COUNTROWS ( FILTER ( 'Calendar', NOT ISBLANK ( Combined[Sum of Amt] ) ) ) ) - mcmullenrich4 years agoFrequent Visitor
Yes, that's correct
- tamerj14 years ago
Community Champion
Then I hope the last solution works.
- tamerj14 years ago
Community Champion
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? - mcmullenrich4 years agoFrequent Visitor
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 )