So the dates arrive in string format.
I am trying to convert to timestamp and finding the largest value/newest timestamp.
I am having a hard time to convert from string to tick and then to timestamp, all the while ending up with only the largest date.
My formula
addToTime('0001-01-01T00:00:00Z', div(max( ticks(formatDateTime(items('For_each_2')?['document_date'])),ticks(formatDateTime(items('For_each_2')?['requested_date'])),ticks(formatDateTime(items('For_each_2')?['promised_date'])),ticks(formatDateTime(items('For_each_2')?['shipment_date'])),ticks(formatDateTime(items('For_each_2')?['posting_date']))),10000000),'second')
The error
InvalidTemplate. Unable to process template language expressions in action 'Update_item' inputs at line '1' and column '3049': 'The template language function 'addToTime' could not create time value with time interval '-701917440' and time unit 'second'. It results in an out of time range value.'.
The right expression should be like below shows:
addToTime('1970-01-01T00:00:00Z',div(sub(variables('maxticks'), 621355968000000000),10000000),'second')
Firstly I get the max ticks with the below expression from three date:
int(max(ticks(formatDateTime(triggerBody()['now'])),ticks(formatDateTime(triggerBody()['yesterday'])),ticks(formatDateTime(triggerBody()['tomorrow']))))
Then get the max timestamp:
Related
I am trying to replicate a report in a Visual Studio in Power BI report builder, however I have a column where I am trying to use an expression to dynamically calculate an average of set metrics using from- and to- date parameters i.e whenever I choose a range of date parameters, it dynamically gets the average of that metric depending on the number of months specified, expression also has a logical expression where "if value of parameter A is indicated, it does the metrics calculation based on that value, otherwise it calculates the expression based on the other parameter value. Each time I run the expression, I get error code:
There is an error on line 0 of custom code: [BC30035] Syntax error.
Below is the expression;
=IIF(Parameters!UnitofMeasure.Value= "A",
Code.DivideBy(
Code.SumLookup(
LookupSet(Fields!SubvalueA.Value, Fields!SubvalueA.Value, Fields!MVA.Value, "DatasetA")
)
,CSTR(DATEDIFF(Dateinterval.Day, CDATE(TRIM(Parameters!FromDateRange.Label)), CDATE(TRIM(Parameters!ToDateRange.Label)))) + Code.DaysInMonth(CDATE(TRIM(Parameters!ToDateRange.Label)))
)
,Code.DivideBy(
Code.SumLookup(
LookupSet(Fields!SubvalueA.Value, Fields!SubvalueA.Value, Fields!IVA.Value, "DataSetA")
)
, CSTR(DATEDIFF(Dateinterval.Day, CDATE(TRIM(Parameters!FromDateRange.Label)), CDATE(TRIM(Parameters!ToDateRange.Label)))) + Code.DaysInMonth(CDATE(TRIM(Parameters!ToDateRange.Label)))
)
)
I need someone to help me look into this. Also, I have tried to use the 'values' instead of 'label' for the date range parameter but no difference. The date range in the values and labels are in varchar data types, the values in the date range is in the format of '201901' while label i.e what users see '2019 - Jan'. Thanks
I have a table with column "date" in YYYY-MM-DD format HH:MM:SS:MMM (2015-01-27 11:22:03:742). I'm trying to make a time series with the dimension of month/year grouping, to display the total number of records by period.
Settings:
period dimension: date (type: date and time)
period: date (type: year and month)
metric: record count
My time graph doesn't display anything. Can someone help me identify what's going on?
formatDate is the column created with the expression:
PARSE_DATETIME("%Y-%m-%d %H:%M:%S",REGEXP_EXTRACT( create_date,"(.*):[0-9]*"))
Using the date in its standard format, as mentioned at the beginning of the question, the same happens.
When entering dates (original and formatted), both appear with null values.
The milliseconds have to be separated by a . not a :. An option is to import your date a as string/text and add a calculated field, which parse the string in Data Studio:
PARSE_DATETIME("%Y-%m-%d %H:%M:%S",REGEXP_EXTRACT( data_field,"(.*):[0-9]*"))
If the dates are several years in the past, please adjust the Default date range in your graph:
I leave the solution to my problem to the community.
The problem is in the date format. Failed to get Google Data Studio to receive a date with milliseconds. By removing the milliseconds it was possible to work with the dates normally, managing to apply the available functions.
Note: It may be a knowledge limitation, but none of the date formatting functions work if the datetime field contains milliseconds (FORMAT_DATETIME, PARSE_DATETIME,...)
I linked Firebase to BigQuery and start using Google Data Studio to create a table to list users by "User Pseudo ID".
My goal is to calculate the difference between two dates, the date of first_open and the date of app_remove to come up with an average retention time.
How can I write the right query in Data Studio?
It can be achieved using the three step process below:
1) HH:MM:SS
The Calculated Field below uses the DATETIME_DIFF function to find the difference between app_remove and first_open, and displays the difference in SECOND (for future reference, set the third input DATETIME_DIFF as required, for example, to view the difference in days, set the input to DAY):
DATETIME_DIFF(app_remove, first_open, SECOND)
2) Type (HH:MM:SS)
Number > Duration (Sec.)
3) Aggregation (HH:MM:SS)
AVG
Google Data Studio Report and a GIF to elaborate:
DATE_DIFF may be what you are looking for.
That is if first_open and app_remove are date fields or date expressions
Using Solr 8.0.0, with each document holding a start timestamp field and an end timestamp field, how would I query in a way that returns just the duration between these dates? So I would be going for an equation like this:
(Endtime - Starttime) - 500 seconds = 23 seconds over expected duration.
But getting the result across all documents in the collection.
Would this be the subject of a streaming expression? Any example code you can give? I specifically want to keep this calculation load within the SolrCloud.
You can use a function query. The ms function gives you the difference in milliseconds between two dates. You can use sub to subtract 500 seconds from that number.
You can use the frange query parser to filter documents that match a given range. Which means we end up with something like:
q={!frange l=0}sub(ms(endtime,starttime),500000)
I am trying to make a simple scatter plot in MATLAB with time on the x-axis and wind speed on the y-axis. I loaded in my data from a text file as a table and then tried to use table2array to plot since it needs numeric values not table data. I also tried using double and got another error.
Error Message: Error using scatter (line 55) Input arguments must be numeric or objects which can be converted to double.
Error in windconversions (line 18) scatter(time,wnd_TS)
I'm not sure if having the times as strings will also be an issue.
T = readtable('allunderway.txt', 'HeaderLines', 2);
%A = table2array(T)
date = T(:,1);
time = T(:,2);
wnd_TD = T(:,10);
wnd_TS = T(:,11);
table2array(wnd_TS);
table2array(time);
%double(wnd_TS);
scatter(time,wnd_TS)
A simpler way to access the data contained within the table is to use the dot notation, as T.VarN, where N is the number of the column you are interested in.
In your code you are using only 'time' for the plot, however this consists of hours, minutes and seconds only. I suspect that for your graphical analysis you require the combination of both the date and the hours.
It is possible to perform arithmetic addition on datetimes, however it is required that the two variables have the same format. By converting both dates to format 'MM/dd/yyyy HH:mm:SS' you are actually modifying the data of the variables. However, as stated in the documentation:
Since the data in the first column of the file ("date") have no time information, the time of the resulting datetime values default to midnight. Since the data in the second column of the file ("time") have no associated date, the date of the datetime values defaults to the current date.
When you add the variables date and time together together, you can add the date ('MM/dd/yyyy') of date to the time ('HH:mm:SS') of time.
An example of datetime conversion and addition follows.
Variables date and time before conversion:
date = 05/04/2011
time = 00:00:42
After conversion:
date = 05/04/2011 00:00:00
time = 06/01/2018 00:00:42
Adding the two:
05/04/2011 00:00:42
The code which reads the table and plots the scatter graph:
%Read table.
T = readtable('allunderway.txt', 'HeaderLines', 2);
%Access data of interest from table.
date = T.Var1;
time = T.Var2;
wnd_TS = T.Var11;
%Convert variable time to datetime.
time = datetime(time,'Format','HH:mm:SS');
%Add hours, minutes and seconds to variable date.
date = datetime(date,'Format','MM/dd/yyyy HH:mm:SS');
%Add month, day and year to variable time.
time = datetime(time,'Format','MM/dd/yyyy HH:mm:SS');
%Combine date and time variables.
fullt = date+timeofday(time);
scatter(fullt,wnd_TS);
The output of the code is the required scatter graph:
You can find more information on combining date and time from separate variables here.
Why do so much extra work. You could have simply used scatter(datenum(T.time),T.wnd_TS). That should do the job and save all the extra effort.