Trying to Average number of accounts by hour, day of week, and month - tableau-api

I'm in healthcare and we're trying to assess the number of discharges we have per hour of day, but we'd also like to be able to filter them down by day of week, or specific month, or even a particular day of week in a particular month (e.g. " what is the average number of discharges per hour on Mondays in January?")
I'm confident that Tableau can do this, but haven't been able to make the averages show up in my line graph... every time that I convert it from COUNT to AVG, the line simply goes straight. I got close when I did a table calculation to find the Average (dividing the count per hour by the number of days captured in the report), but when I add a filter for either the month or day of week, selecting one of the options of the filter reduces the total number that is being counted, rather than re-averaging the non-filtered items. (i.e. if the average of the 7 days of the week is "10" for a particular hour, and I deselect the first three days of the week, it's now saying that my average for that hour is roughly 6, despite the fact that all of the days are very close to 10 at that hour.)
Currently, my data table has the following columns:
Account#/MonthYear/HourOfDay/DayOfWeek
ex.12345678/ Jan-17 / 12 /Sunday

I would just create a few calculated fields to differentiate the parts of the calendar you might want to filter/aggregate on. Mixing the month and day of the week with filtering is pretty straight forward with the calculated fields. Then do standard summing to get what you are looking for because an average count of records is always one unless you are throwing some other calculation into the mix. I threw a quick example up on Tableau Public for you to get the idea.

Related

Why are my values multiplying when I apply Month/Year to my values?

When I apply Month/Year to Cases or Deaths from my data, the values explode. For Cases it goes from approximately 48 million to over 1 billion, and for Deaths it goes from about 700 thousand to over 22 million. However, when I try the same thing with Initial Claims or the Stringency Index, my values remain correct. I'm trying to find the month over month percentage change by the way. And I'm using the Date column. I only select 2020 and 2021 in the filter for Year.
What I'm asking about is Sheet 21.
Link to workbook: https://public.tableau.com/app/profile/nilajah.rivers/viz/CoronaVirusProject_16323687296770/Sheet21
Your problem is that the data points are daily cumulative deaths. If you change the date aggregation to anything other than days, Tableau will default to summing the numbers for all the days in the month. This will give the wrong result, obviously.
If you want to show the correct total deaths or cases regardless of the time aggregation (months, days, weeks etc.) then you could use the New Case or New Death numbers plus a running sum table calculation. This will always give the correct total for the time period.
Table calculations will also allow automatic calculation of the period to period % change from the same data fields.
This is a common problem when working with datasets that offer pre-calculated aggregations. Tableau doesn't need that as it can dynamically calculate the aggregation of a field over any given time period but it is easy to forget which field has pre-aggregated data and which has raw data. Pre-aggregated fields assume a particular time period and can't be used for different time periods without disentangling that assumption (which is unnecessary if you also have the raw data (in this case daily new deaths/cases).

Can I calculate a moving sum on a field in InfluxDB?

I'm trying to understand if it's possible to calculate a 1 month sum of revenue data in one of my measurements. For each day, I would like the sum of the previous 30 days.
Is this possible in InfluxDB or through Grafana's query interface?
A moving average is a moving sum, divided by the number of samples. So if you want a moving sum of the past 30 values:
select 30*moving_average(field_name, 30) from measurement
Edited to add:
As Peter Halicky points out in the comments, this is is not the past 30 days. It's the past 30 data points.
If you will always have data for every single day, it's not an issue.
If you're missing a day's data, you'll still get a 30-sample average, but it'll stretch over 31 days instead of 30.
If you don't actually care about the calendar, but want to know the past 30 days of activity, this is not a problem.
If it is a problem, there are a few work-arounds. One that's probably trickier than it sounds: ensure that there is always an entry for each day.
A more robust way is to have the reporting app do this in two steps. Something like this (haven't worked out all the details, but you get the idea):
find the number of data points in the past 30 days, using a query like select count(field_name) from measurement where time > now() - 30d.
Use this number (call it n) to form the query: select n*moving_average(field_name, n) from measurement where time > now - 30d.
Yes, definitely it's possible.
Just set this part of your query like this:
SELECT sum("value") FROM "YOUR_TAG_NAME"
WHERE $timeFilter GROUP BY time(30d) fill(null)
Just make sure that your dashboard time included Last 30 days (at least).

DRUID : Get Number of days for a given date range to get average

Need to have the total number of days for a given interval. I have already tried using distinct of dates for the purpose. It fails because for some days data is not present. Once I have the number of days for the given date interval I will be able to find the daily average.
Any other approaches is also welcomed

Average Volume Every Weekday In a Month Tableau

I am trying to calculate an expression in Tableau 10.2 for a contact center use case.
I have calls at every hour all days of the week.
I need to calculate the average call per hour per day. For instance i need to calculate the average call every Sunday at 9 pm and use that in tool tip.
By this i am measuring how many average calls we get on a given Sunday or any other day of the week at a particular hour.
I had written an expression sadly that is not resulting in accurate number
AVG({ FIXED [Weekday Flagging],[Hour]:
AVG([Volume])})
Do suggest.
Very Recently I had a same requirement to see avg visitors on the hours of all the days of a week. My requirement was (Total No. Of Visitors on Sundays/No.Of Sundays) and then (Total No of Visitors #hour/No. Of Sundays).
1)create a calculated field : sum(volume)/countd(date) and name it 'Avg Volume'
2)drag date to 'Columns'. From the drop down click 'More' -> 'Weekday'
3)drag the calculated field to rows. This will give avg volume on each days of a week.
To get Avg Volume of hours
1)do the same procedure as above and instead of 'Weekday', drag Hour of the day to the column.
Link these 2 sheets using an action filter, so that if u click on sunday in the first sheet, it will show the avg volume of each hour of sunday in the second sheet.

Use Number of Values selected in a Filter inside a Calculation Field

In Tableau, I have a Date Filter with 31 days (days in a month).
I have a calculation,
Sum(sales)/(No of days)
Based on no of days selected in the Date Filter, my calculation should change.
Eg : If 12 days are selected in filter
The Calculation should be Sum(sales)/12
If 20 days then Sum(sales)/20.
Regards
Try this formula
sum(Sales) / datediff('day', min(Date), max(Date))
Just realize that if you have missing data at the start or end of your period, say no entries at all for the first few days of the month, it will only start counting days at the very first day of data, i.e. min(Date)
For those reasons, it is often useful to pad your data to have at least one row per day, even if it most of the fields are null in the padded data row. You can use a union or left join to do that without disturbing your original data.