Calculating total number of days based on the relative date range filter in tableau - filter

I have a date column using which I created a "relative date" filter as follows:
Now I want to create a measure as follows:
SUM(value from another column)/total number of day in that date range.
Can someone help me how to create this measure?? Thanks!!

Assuming you Record Date field is at the day level of detail, you could do:
SUM(value from another column)/countd(record_date)

Related

Tableau - Fixed calculated field depending on date filter

I'm new to Tableau. I am trying to make an inventory report which tells the user how much of certain product he/she should buy in advance.
Depending on the amount of days selected on the filter, the difference in days of the complete period should be calculated. For example: If the filtered dates are from 1/03/2021 to 09/03/2021, the result should be equal to 9. The formula I used is the following: date_difference = DATEDIFF("day",MIN(DATE([Fecha])), MAX(DATE([Fecha]))) + 1
The problem comes when I try to use the value given by such date filter. My next calculation should be:
calc = Quantity Inventory / (Units sold / date_difference). Both Quantity Inventory and Units sold are calculated fields in which I have no problem. However, instead of having a fixed value of 9, date_difference changes as shown in the image, giving me incorrect results for the desired calculation.
How can I make sure that the calculated field date_difference has the value of 9 on all rows?. Actually, if I add date_difference field by itself in a different Page it does show the proper value. The problem occurs when calculating calc and trying to add it to the table.
Note: Remember that the value of date_difference will change, depending on the range of time selected on the date filter
Thanks a lot in advance.
Step-1 Use this calculation for date_difference instead
DATEDIFF('day', {min(DATE([Fecha]))}, {max(DATE([Fecha]))}) +1
Step-2 Add Fecha filter to context, by right clicking it in filters shelf.
This will solve your problem. See the GIF

Kibana subtracting the values of 2 indices

I have 2 indices in kibana 4:
1st index is basing time from events (Date Created)
2nd Index is basing time from events (Date Closed)
Both are date values and I want to create a query which will return the total amount of docs Date Created (Today) - total amount of docs Date Closed (Today)
If this is not possible is it possible if i have both fields in one index?
Yes you need to have both the date values within the same index so that you can do the subtraction using a scripted field in Kibana. You could simply have your script as such:
doc.['date_created'].value - doc.['date_closed'].value
----------------^----------------------------------------^ Make sure to give your exact field names
And then you could use this scripted field as a Date Historgram to show the total count of the docs within the retrieved date range.
Hope this helps!

Comparing data in kibana

I am indexing user data for each day and using Kibana to analyse it, so far I am able to visualize all my requirement. But I am not able to visualize following use case
I want to analyse total number of user,repeated number of users from previous day and how many are unique.
I can visualize total number of user for day , but how do I compare today's data from yesterday.
Any help appreciated.
Thanks in advance
I hope I understand your requirement correctly, but you could create a Vertical Bar Chart visualization with Kibana and change the default 'Count' to 'Unique Count', select the field you like to do the unique count for and then add an X-Axis with a date histogram on your timestamp field.
This will create a bar chart and each bar will contain the unique count for each time interval. So if you select 7 days as your timeframe and 1 day interval in your X-Axis date histogram, you'll see the unique count per day.

DAX - Sum Workdays By Month within Range

I've been at this one a while.
Objective: Pivot a monthly summary of days worked by Resource within the range for that Resource line where those dates (from StartDate to EndDate) correspond to the Dates table IsWorkday field.
Thanks for your help!
It depends on how you define what a workday is. I suspect this is Monday thru Friday? If so, try the weekday function.
=WEEKDAY(serial_number,2)
Where serial_number is the cell with a date you want to identify. This would not exclude holidays, I would recommend an index/match on some holiday reference table for that.
https://support.office.com/en-us/article/WEEKDAY-function-60e44483-2ed1-439f-8bd0-e404c190949a

How can I select entries for a given weekday using SQL?

I could use this query to select all orders with a date on a monday:
SELECT * from orders WHERE strftime("%w", date)="1";
But as far as I know, this can't be speed up using an index, as for every row strftime has to be calculated.
I could add an additional field with the weekday stored, but I want to avoid it. Is there a solution that makes use of an index or am I wrong and this query actually works fine? (That means it doesn't have to go through every row to calculate the result.)
If you want all Mondays ever, you'd need a field or sequential scan. What you could do, is calculate actual dates for example for all Mondays within a year. The condition WHERE date IN ('2009-03-02', '2009-02-23', ...) would use index
Or as an alternative to vartec's suggestion, construct a calendar table consisting only of a date and a day name for each day in the year (both indexed) and then perform your query by doing a JOIN against this table.

Resources