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
warwick
Regular Visitor

Average number of tickets by day of week

This is the format of my data, in my Tickets table.

2016-11-17 09_34_14-Clipboard.png

I'd like to graph the average number of tickets by weekday over the past three months, i.e. On Mondays we get an average of 5 tickets logged.

I've read a couple of other posts and attempted to apply the logic to my situation but I'm having trouble doing so.

Any help would be appreciated!

2 ACCEPTED SOLUTIONS

sorry - my bad.  I overlooked the fact that you wanted to report by day.  

 

Try this

 

Average Tickets 13 weeks =
    CALCULATE (
        DIVIDE ( [Total Tickets], DISTINCTCOUNT ( Calendar[WeekID] ) ),
        FILTER (
            ALL ( calendar ),
            calendar[WeekID]
                >= MAX ( calendar[weekID] ) - 12
                && calendar[WeekID] <= MAX ( calendar[WeekID] )
        ),values(calendar[day])
    )

where Calendar[Day] is the field you have on your chart axis.



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

You have a time stamp as part of your date entered column in the tickets table.  If you don't need this time, then simply remove it during load (format as date). If you do need it, split the column before loading so you have a pure date column and a time column.  



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

16 REPLIES 16
Anonymous
Not applicable

 
v-shex-msft
Community Support
Community Support

Hi @warwick,

 

You can create a summary table to calculate the result:

 

Table.

Capture.PNG

 

Calculate table.

 

Formula:

Summary Table = DISTINCT(SUMMARIZE(ticket,ticket[Date],"Count",COUNT(ticket[TicketID])))

 

Calculate columns.

Average of last three Month = if(
AND([Date]>=DATEADD(LASTDATE(ALL(ticket[Date])),-3,MONTH),[Date]<=TODAY())&&AND(WEEKDAY([Date],1)<>1,WEEKDAY([Date],1)<>7),
AVERAGEX(
FILTER('Summary Table',
AND([Date]>=DATEADD(LASTDATE(ALL(ticket[Date])),-3,MONTH),[Date]<=TODAY())&&
WEEKDAY([Date])=WEEKDAY(EARLIER([Date]))),
[Count]),BLANK())

 

DayofWeek = SWITCH( WEEKDAY([Date],1),1,"Sunday",2,"Monday",3,"Tuesday",4,"Wednesday",5,"Thursday",6,"Friday",7,"Saturday")

 

Result:

Capture2.PNG

 

Capture3.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I'm getting an error here related to having duplicate dates in the date column, due to multiple tickets being logged on the same date at different times, know any way around that?

Who's instructions did you follow?  This should not happen with my approach.



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Sorry, thought it would give the context as to who I was replying to when I clicked reply on Xiaoxin_Sheng's post. I tried your method as well, Matt see below:

 

Date Table created:

 

2016-11-24 15_17_18-types - Power BI Desktop.png

 

Average Tickets Measurement created on the tickets table:

2016-11-24 15_18_41-types - Power BI Desktop.png

Total Tickets measurement created on the tickets table (srsearchscreen)

 

2016-11-24 15_19_10-types - Power BI Desktop.png

 

And finally the graph:

2016-11-24 15_22_55-types - Power BI Desktop.png

 

However it isn't matching what we should be seeing, specifically a massive dip on Weekends. Additionally when I filter what we're seeing by the board the ticket is logged to the graph is blank.

sorry - my bad.  I overlooked the fact that you wanted to report by day.  

 

Try this

 

Average Tickets 13 weeks =
    CALCULATE (
        DIVIDE ( [Total Tickets], DISTINCTCOUNT ( Calendar[WeekID] ) ),
        FILTER (
            ALL ( calendar ),
            calendar[WeekID]
                >= MAX ( calendar[weekID] ) - 12
                && calendar[WeekID] <= MAX ( calendar[WeekID] )
        ),values(calendar[day])
    )

where Calendar[Day] is the field you have on your chart axis.



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Doesn't look like that's having the intended effect...

2016-11-28 09_45_11-New1 - Power BI Desktop.png

 

Feel free to have a go with this excerpt of data, https://www.dropbox.com/s/jvjnkq97gpkne4h/tickets.csv?dl=1

Once again, appreciate the help!

I have already tested it with my own data and it works.  If you would like further help, please post a sample of the workbook that isn't working so I can investigate. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Yes, I saw that - but this is just a CSV file.  I can't check what is going wrong unless you post a workbook that has the DAX formulas.  As I mentioned, I have already tested it with my own data and it works perfectly.



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Here is my PB workbook: https://www.dropbox.com/s/eb2qmunkit5whq5/Average%20TIckets%20by%20Weekday.pbix?dl=1

Using the csv from before as the datasource.

 

Thanks

You have a time stamp as part of your date entered column in the tickets table.  If you don't need this time, then simply remove it during load (format as date). If you do need it, split the column before loading so you have a pure date column and a time column.  



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Hi Matt,

 

See the link in my post just above yours for the data in question.

 

Cheers,

 

Warwick

 

That's fixed it. Thanks again for your help, @MattAllington

@warwick - I have looked at your PBIX and there was an initial issue with the entered date in that it included time, I created a seperate colum to remove this so that way the Calendar table could link properly to the tickets table.

 

Tickets.PNG

 

Thanks Giles

 

you need a calendar table first.  Make sure the calendar table has the day of week column included, plus a WeekID column that is 1 for the first week, 2 for the second week....8 for the 8th week, 9 for the 9th week etc.

 

read about that here http://exceleratorbi.com.au/power-pivot-calendar-tables/

 

Join the calendar table to your date column.

put the day of week on your chart axis.

write the following measures

 

Total Tickets = countrows(TicketTable)

 

Average Tickets 13 weeks =
    CALCULATE (
        DIVIDE ( [Total Tickets], DISTINCTCOUNT ( Calendar[WeekID] ) ),
        FILTER (
            ALL ( calendar ),
            calendar[WeekID]
                >= MAX ( calendar[weekID] ) - 12
                && calendar[WeekID] <= MAX ( calendar[WeekID] )
        )
    )

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Im sorry, why is that you need to substract -12 in the formula?

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.