If i have a column like this
How would i convert this into seconds?
In PowerQuery change the type of the column to Date/Time
Add a Custom Column with the formula
= ([business_duration] - #datetime(1970,1,1,0,0,0)) * 24 * 60 * 60
Change the type of the new column to Whole Number
You can use this function:
let
fun_DateTimeFromUnix = (DateTime as number) as datetime =>
let
Source = #datetime(1970,1,1,0,0,0) + #duration(0,0,0,DateTime)
in
Source
in
fun_DateTimeFromUnix
As shown:
Related
I have a PowerBI dashboard that contains casino guest information, including their latitude and longitude coordinates. The dashboard allows a user to input a zip code and select a radius around that zip (slicers). When doing so, it filters the table of casino guests to only those with a distance (measure) less than or equal to the radius chosen. I used this distance measure and logic to create another measure "InRadius" that would show 1 or 0 depending on if the given guest is within the radius. then used this "InRadius" measure as a filter for my table, as well as other visuals. everything works fine, except I am wanting to add a "between" slicer that will filter guest's ADW Range and I am unable to filter this slicer by my measure "InRadius", therefore my min and max values for ADW in the slicer, do not accurately reflect the ADW ranges for guests filtered in my table. Is there any way for me to get around this? Is it possible to create a new measure that I could use specifically for this slicer? Is it possible to filter a slicer by only the values present in an already filtered table? In general, I am just wanting to create a slicer that filters a columns values based on a measure's value, but can't figure out how to go about accomplishing it.
some codes I have tried while creating a new measure but haven't given desired result:
InRadiusADWFilter = IF([InRadiusPatron]=1, VALUES(TF_MapRadius[ADWNet]))
InRadiusADWFilter = FILTER(VALUES(TF_MapRadius[ADWNet]), [InRadiusPatron]=1)
InRadiusADWFilter = CALCULATE(VALUES(TF_MapRadius[ADWNet]), [InRadiusPatron]=1)
Here is my code for my measure distance:
// Haversine/great-circle distance calculation adapted from Stack Overflow: https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula
VAR __latSelected = SELECTEDVALUE('TF_MapRadius'[maplat])
VAR __lonSelected = SELECTEDVALUE('TF_MapRadius'[maplong])
VAR __radius = 3956
VAR __multiplier = PI()/180
VAR __latDiff = (MIN('Selector'[Latitude])-__latSelected) * __multiplier
VAR __lonDiff = (MIN('Selector'[Longitude])-__lonSelected) * __multiplier
VAR __formula1 =
SIN(__latDiff/2) * SIN(__latDiff/2) +
COS(MIN('Selector'[Latitude]) * __multiplier) * COS(__latSelected * __multiplier) *
SIN(__lonDiff/2) * SIN(__lonDiff/2)
VAR __formula2 = 2 * ATAN(DIVIDE(SQRT(__formula1),SQRT(1-__formula1)))
VAR __distance = __radius * __formula2
RETURN __distance
here is my code for the measure "InRadius":
InRadiusPatron = if('TF_MapRadius'[Distance2] < Radius[Radius Value],1,0)
I've created dummy table that represents my filtered table:
ID
PatronName
ADWNet
Distance
InRadius
1
Smith, John
325,555
5.2
1
2
Jobs, Steve
200
7.0
1
3
Jeter, Derek
90,000
10.1
1
4
Jordan, Michael
-2,567
14.5
1
If you have measure that returning 1/0 (for example InRadius), then you can filter your visualization (select it and go to filter pane).
I need to create a dashboard which can show duration in 00:00 based on given month or year. I managed to use DAX to create a calculated column that can show similar thing in the table. But I'm unable to use the value in that column to display due to they are strings.
How can I create a DAX measure instead of a caculated column to display the sum of duration in 00:00 format and present them in the dashboard?
AHT In MM:SS =
SUMX('Raw Call',
VAR M = PATHITEM(SUBSTITUTE('Raw Call'[AHT],":","|"),1)
VAR S = PATHITEM(SUBSTITUTE('Raw Call'[AHT],":","|"),2)
REtURN CONCATENATE(M, CONCATENATE(":", S))
)
When you need to sum up all the value of minutes and seconds, you will need to convert the string format into number then you can start the calculation, however I am unable to provide a single step solution but would need some helper column to do so:
Multiple steps
First, from the "AHT" column you already created, I will obtain the minutes portion by creating a new column:
minutes = VALUE(LEFT(Sheet1[Time],2))
Next, I will create a new column to store the seconds also:
seconds = VALUE(RIGHT(Sheet1[Time],2))
Finally, I will create a new measure to sum the duration of minutes and seconds with the following formula:
duration =
var sec = MOD(SUM(Sheet1[seconds]),60)
var minute = TRUNC(DIVIDE(SUM(Sheet1[seconds]),60)) + SUM(Sheet1[minutes])
return
FORMAT(minute,"General Number") & "minutes " & FORMAT(sec,"General Number") & "secs"
Here is my original table with two new columns:
By setting the calculated measure as field, I will get the following scorecard, you may choose other format like "00:00" if you prefer :)
Single step to return the same result using dax formula with measure:
Duration =
var minutes = SUMX(Sheet1,VALUE(LEFT(Sheet1[Time],2))) + SUMX(Sheet1,TRUNC(DIVIDE(Sheet1[Time],60)))
var seconds = MOD(SUMX(Sheet1,VALUE(RIGHT(Sheet1[Time],2))),60)
return
FORMAT(minutes,"General Number") & " minutes " & seconds & " seconds"
Currently , I have date column in time format ,I want to change it to date time stamp format I.e ( I want the date column to look like 12nov 2020 12:03:45:00 )
Could someone help me on this ?
According to #KurtBremser:
SAS dates are counts of days, SAS datetimes are counts of seconds.
datetime = dhms(date,0,0,0);
will convert a date to a datetime. Or multiply by 86400.
A column showing a time representation hh:mm:ss can be one of three things:
A character column type containing digit characters 0-9 and :
A number column type containing a SAS time value being displayed as hh:mm:ss with the time format TIME8.
A number column type containing a SAS datetime value being displayed as hh:mm:ss with the datetime format TOD.
This sample program demonstrates how different kinds of values can all look the same when viewed.
data have;
v1 = '12:34:56';
v2 = hms(12,34,56);
v3 = dhms(today(),12,34,56);
put v1= / v2= time8. / v3=tod. / v3=datetime18.;
run;
------ LOG ------
v1=12:34:56
v2=12:34:56
v3=12:34:56
v3=25NOV20:12:34:56
Only #3 has enough information in the raw value to be formatted as ddmmmyyy:hh:mm:ss
format myDate datetime18.;
#2 requires computing a new value assuming something about the date part
* supposing myDate contains only time values (00:00:00 to 23:59:59) for today;
myNewDate = dhms(today(),0,0,0) + myDate;
format myNewDate datetime18.;
#1 requires interpretation through INPUT and a date assumption
* supposing myDate contains "hh:mm:ss" for today
myNewDate = dhms(today(),0,0,0) + input(myDate,time8.);
format myNewDate datetime18.;
I need to obtain the time difference in minutes between a row and the one that follows. I would like to use the field DATE to calculate and maybe create an additional field with the new measurement.
This is the structure of my fields in my database.
You should be able to use the TRANSACTION number to look up the prior row.
Something like this as a calculated column:
Diff = 24 * 60 *
(Table1[DATE] -
LOOKUPVALUE(
Table1[DATE],
Table1[TRANSACTION],
Table1[TRANSACTION] - 1
)
)
Note: The difference has units of days, so the 24 (hours/day) * 60 (minutes/hour) is the conversion you need.
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