Given these two timestamps/converted to datetimes:
Start - 1668105400.814 - Thursday, November 10, 2022 12:36 PM
End - 1668444427.195 - Monday, November 14, 2022 10:47 AM
...how can I get the number of seconds, adjusted for "business" days? With this example, you'll see that the start date was a Thursday (Friday was a holiday in Canada), and the end date was a Monday. Taking holidays into account isn't super important here, would be nice, but for simplicity of the solution, it would be cool to subtract 172800 seconds (2 days' worth) from the difference between the End and the Start if it stretches over a weekend.
My dataset looks like this:
type created_at emitted_at
assign 1668105400.814 1668105400.814
archive 1668105400.814 1668444427.195
How I'm currently calculating the number of seconds is in an added custom column with the formula:
_Created_To_Archive_Handle_Time = IF(Front_Email_Stats[type]="archive", ROUND((Front_Email_Stats[emitted_at] - Front_Email_Stats[conversation.created_at]), 1), BLANK())
...where it filters for type of archive only, and then subtracts the archived emitted_at timestamp from its created_at timestamp.
A naive approach would look something like this:
_Created_To_Archive_Handle_Time = IF(Front_Email_Stats[type]="archive", IF(AND(WEEKDAY(Front_Email_Stats[_created_at_datetime_custom_column]) < 7, WEEKDAY(Front_Email_Stats[_emitted_at_datetime_custom_column]) > 1), ROUND((Front_Email_Stats[emitted_at] - Front_Email_Stats[conversation.created_at]), 1) - 172800, ROUND((Front_Email_Stats[emitted_at] - Front_Email_Stats[conversation.created_at]), 1)), BLANK())
...where we filter for archive types only, and then do a simple check if the Start timestamp's day of week is less than Saturday (7 I think?) and the End timestamp's day of week is greater than Sunday (1?), but wondering if there's a more elegant solution.
Use NETWORKDAYS() and then subtract the seconds manually.
https://learn.microsoft.com/en-us/dax/networkdays-dax
Related
I want to always get the date for the most recent last Saturday since current date, and I'm trying this query:
date_trunc('week', current_date) - interval '2' day
This would work if today is Monday - Saturday, but if the day is Sunday, it would return the last Saturday rather than yesterday.
Example:
If I put 2021-07-18 as current_date, I want it to return 2021-07-17, but it actually returns 2021-07-10.
I guess this is because presto treat a week as Monday - Sunday, rather then Sunday - Saturday?
How can I solve this problem? Thanks!
Add two days, truncate, then subtract two days:
select date_trunc('week', current_date + interval '2' day) - interval '2' day
I'm interested in creating a report comparing a before and after of two equivalent time periods.
The after period is looking at the days from a fixed date (1/10/20) to the most recent case in the tbl_Data table (in this case it is 92 days).
The before period would subtract the calculated 92 days from the fixed date (1/10/20).
I was able to get the days between part fairly easily using the following:
Days_Between =
calculate(
countrows(date_table),
DATESBETWEEN(
date_table[Date_field].[Date],
date(2020,10,01),
MAX(tbl_Data[Date Received])
)
)
However I'm at odds on how to subtract this from the fixed date to get a date range I can filter on easily. Any pointers/ideas would be greatly appreciated.
Cheers
First, I would simplify your days calculation: Days_Between = DATEDIFF(date(2020,10,01), MAX(tbl_Data[Date Received]), DAY ). Then, I would simply subtract the result from the given date. Start date = Date(2020, 10, 1) - [Days_Between]
I am creating a report with buttons that use a slicer to show the last 3 calendar months, the default view, and YTD. The first two are all set and will continue to work fine, however i am having trouble with the YTD filter because i need it to exclude the current month (some of the key metrics for this slicer are only accurate monthly, even thought the data is updated Daily). Any idea how to accomplish this without me having to manually change it every month? An example of it working today would show me 2020 through August, since September is not complete. September would be included in the filter starting October first. I am thankful for your help/insights!
I typically build a calculated column on my date table called something like "Date in Range", that looks something like the below. You could also apply this to a date in a normal table if you are not using a date dimension.
Date in Range = IF ('MyTable'[Date] <
DATEADD(TODAY(), -1 * DAY(TODAY()), day),
1,
0)
This compares the date in the table row with TODAY(), e.g. 14 Sep 2020, minus the day of the month of today (14), effectively getting you back to the start of the current month. This will then return 1 for dates before the end of last month or 0. Filter on 1 or 0 to get your result (or use something more meaningful in place of the 1 or 0).
I need to make a total for each of the months based on the working days.
So far i have working days set as 1 if the day in the month is during Monday - Friday and 0 for Saturday and Sunday. I now need to total up the 1's and make it so that it is a single value for the month.
E.g Going the weekdays is 1 and weekend is 0, January will have 22 days on each row on the table in the data mode - January 1 = 232 January 2 = 22 etc. so i can use it to divide against my target which is set to the 1st of every month.
How can i do this??
try this. i haven't tested it.
=GROUPBY( FILTER(table, table[Working_Day]=1) , table[Month], ["new col", SUMX( CURRENTGROUP(), table[Month_Order])])
filter gives working day 1's data as table,then group by performed by month, then month order has been added and returns table.
I currently use the below measure to retrieve a value for the previous week, however as it's now week 1 of a new year, the field is returning "blank" as it cannot find any previous weeks.
How would I adapt my measure to include something along the lines of... if week 1 use the last week of the previous year, if not use the previous week.
VAR CURRENT_WEEK = WEEKNUM(TODAY()) return
CALCULATE(AVERAGE(DATA_TABLE[VALUE]),
FILTER (DATA_TABLE, WEEKNUM(DATA_TABLE[DATE]) = CURRENT_WEEK -1))
Thanks in advance for your help
I would suggest using a start date and calculating the weeknum from that date. For example, if you choose 1 Jan 2018 as start date, then 1-7 Jan 2018 would be week 1 and first week in 2020 would be week 105. This would solve your issue.
The method you are using becomes really hard to handle if your data has multiple years. Weeknum 1 would denote the 1st week of 2020, 2019 and all the other years. This will mess up the calculation. The above method will make sure you have a unique number for a week.