As you all might already know, TODAY() function returns UTC time when published to Power BI Service.
Our requirement is to return the local (EST) date. As a solution, we created a custom measure that adds UTC offset hours for EST in NOW() and returns the resultant date.
However, this does not handle daylight saving changes as offset changes during these periods.
What are the possible ways to handle this?
You can try something like this:
ESTnow=
VAR currentTime = NOW()
VAR timeYear = YEAR(currentTime)
VAR dstStart = DATE(timeYear, 03, 14 - MOD((1+FLOOR(timeYear*5/4,1)),7)) + TIME(2,0,0)
VAR dstEnd = DATE(timeYear, 11, 7 - MOD((1+FLOOR(timeYear*5/4,1)),7)) + TIME(2,0,0)
RETURN IF(currentTime >= dstStart && currentTime <= dstEnd, currentTime - TIME(4,0,0), currentTime - Time(5,0,0))
Daylight savings start on the second Sunday of March and end on the first Sunday of November.
A more flexible way to convert UTC date/time for any location (time zone) in the world, and taking Daylight Saving into account, would be to use a Time API service like the one at https://www.timeanddate.com/services/api/time-api.html
Related
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
I am having a bit of tough time wrapping my head around this. I have a column based on response time in hours and our company's SLA (service level agreement) is that all incoming inquires should be answered within 2 days (the response time in hours is total hours spent on responding to inquiry).
The problem is that our company operates with winter time (7 h 45 min) and summer time (7 h). My dataset consist both and I want Power BI to differietiate winter and summer time when I try to compute SLA. In winter time 1 working day = 7 h 45 min and in summer time = 7 h. I have just used the average of summer/winter time = 7 h 30 min. The SLA column consist 3 data types, "Innen en arbeidsdag", "Innen to arbeidsdager" and "over 2 arbeidsdager".
I have used the following syntax:
SLA = SWITCH(TRUE(),Response time in hours>15, "Over to arbeidsdager", esponse time in hours>7.5, "Innen to arbeidsdager", Response time in hours<=7.5, "Innen en arbeidsdag")
How can I use DATESBETWEEN in this syntax to tell Power BI that Response Time YTD column from 15th May to 15th September is summer time, Working day = 7 h?
Just as an idea, I wouldn't use DATESBETWEEN. If you want to input dates directly to logically categorize your work seasons, try this:
SWITCH(TRUE()
,'Date'[Date] >= DATE(2022,5,15)
&& 'Date'[Date] <= DATE(2022,9,15)
,7
,BLANK()--You can carry on with logic for other seasons
)
I am using this syntax on a date table, but you can do this with any table that has a date column.
My dataset is called 'Masterdata' and my columns looks like this:
Svartid i t SLA
6,12 Innen en arbeidsdag
11,73 Innen to arbeidsdager
20,42 Over to arbeidsdager
1,07 Innen en arbeidsdag
etc etc
My syntax so far:
SLA = SWITCH(TRUE(),Masterdata[Svartid i t]>15, "Over to arbeidsdager", Masterdata[Svartid i t]>7.5, "Innen to arbeidsdager", Masterdata[Svartid i t]<=7.5, "Innen en arbeidsdag")
So how can implement
SWITCH(TRUE(),'Date'[Date] >= DATE(2022,5,15) && 'Date'[Date] <= DATE(2022,9,15),7,BLANK()
In my syntax?
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 have to implement in my app where after a user had saved his recording, I will have to determine if 24 hours have passed from the creation date of that recording. So far what I have at the moment is just to determine if current date is not equal to the creation date. I really appreciate anybody's help, thanks in advance.
You can use UserDefault to save the date upon creation of the record. The syntax will be
UserDefaults.standard.set(Date(), forKey:"creationTime")
Whenever you want to check the saved date, retrieve it in this way
if let date = UserDefaults.standard.object(forKey: "creationTime") as? Date {
if let diff = Calendar.current.dateComponents([.hour], from: date, to: Date()).hour, diff > 24 {
//do something
}
}
You can easily check if the time interval since date is greater or equal to a TTL of 24 hours.
let start = Date()
let timeToLive: TimeInterval = 60 * 60 * 24 // 60 seconds * 60 minutes * 24 hours
let isExpired = Date().timeIntervalSince(start) >= timeToLive
I am working on a chat app. I want to determine the time difference between UTC time zone and device current time zone. How to do that in swift3 ?
// Returns a Date initialized to the current date and time
let currentDate = Date()
// Returns the time zone currently used by the system
let timeZone = NSTimeZone.system
// Returns the difference in seconds between the receiver and Greenwich Mean Time at a given date.
let timeZoneOffset = timeZone.secondsFromGMT(for: currentDate) / 3600
print(timeZoneOffset, "hours offset for timezone", timeZone)
// example output for Denver (considers daylight saving time)
// -6 hours offset for timezone America/Denver (current)