Why does RANDARRAY in Excel's "integer" parameter include dates that are outside of the directed min/max values? - date

In Excel, I am trying to create random dates based on three cell values:
Start Date
End Date
Size
Random Dates
2/1/2022
1/31/2023
10
Where "Random Dates" is populated with:
D1: =WORKDAY(RANDARRAY(10,1,A2,B2),1)
Using this formula returns dates within the range, as expected. However, when setting the Integer (I've also seen this called "whole_number") parameter of RANDARRAY to TRUE, it will sometimes select a date outside of the range (i.e., the next business date above the range). See:
D1: =WORKDAY(RANDARRAY(10,1,A2,B2,TRUE),1) Can (and sometimes does) return "2/1/2023" in the spill.
I've tried to look up why this may be for dates, because it doesn't react the same way with numbers. One thought is it has something to do with when it converts the dates selected to integers when INTEGER=TRUE, which may be because it's including time serials in the function somewhere? I'm not sure.
NOTE: "End Date" is not a weekend date and no holidays are used.
I also tried taking WORKDAY away, which doesn't add a date outside of the max value, with either TRUE or FALSE for INTEGER.
I then added type-casted the RANDARRAY as INT:
D1: =INT(RANDARRAY(10,1,A2,B2,TRUE)) which didn't seem to replicate the issue.
But when I added a 5th column with a WORKDAY function in each cell, it then added an additional day again:
E1: =WORKDAY(D1,1) filled down for each of the results.
As soon as I take the TRUE parameter out of cell D1, it goes back to even the values in column E calculating only within the range. This strikes me as Dates passed to RANDARRAY are potentially being calculated with MAX-1 instead of just the MAX provided when INTEGER=FALSE. Which seems like it would be strange behavior.

Related

Google Sheets - IF Statement - Null date (1/1/2500) workaround

I am working on a large nested IF statement that checks several validation points for each row of my sheet. There are several date validations, including chronological order and certain fields not being future dates. However, our system requires that if we must null any dates for processing, that date becomes 1/1/2500, and no matter what I do I cannot seem to get the formula to ignore this date when accounting for future dates or chronology.
//The date cannot be later than the current date - I want this to ignore 1/1/2500
IF(K1<>1/1/2500,"",IF(AND(K1>TODAY()),"Date A cannot be future date",""))
//The two dates must be in chronological order, also ignoring 1/1/2500
IF(U1<>1/1/2500,"",IF(AND(U1>AA1,AA1),"Date A, Date B should be in chronological order",""))
The above approach does not seem to recognize 1/1/2500, even though I got it to work with other dates.
I also tried going with >12/31/2099 (ignore any date greater than 12/31/2099) but it just ignores every date.
Any help would be appreciated.
It looks as though it is failing because K1 is compared to 12/31/2099.
If you use an expression like this in a formula, it will interpret it as an arithmetic expression 12 divided by 31 divided by 2099, which is a very small number, so the greater than test will always be true.
Try starting the formula with Date to convert a year, month, and day into a date.
If(K1>date(2099,12,31)
and you should get the right answer.
See my previous answer for Excel.

Connecting BigQuery and Google Sheets - DATE parameter issue

following 1 I started creating a Spreadsheet which reads data from BigQuery, but I'm having an issue handling parameters related to date values.
In the first sheet, I created 2 cells with 2 parameters, the start and the end of a date interval, with proper values. Both cells are formatted as "Date" value.
In the second sheet I configured BigQuery connector, for this example, I'm using a public dataset with dates. bigquery-public-data.utility_eu.date_greg
From the BigQuery connector wizard I added:
"STARTDATE" as "PARAMETERS!B1"
"ENDDATE" as "PARAMETERS!B2"
After this configuration, this is the resulting query:
SELECT
date,
date_str,
date_int
FROM `bigquery-public-data.utility_eu.date_greg`
WHERE date > DATE(#STARTDATE) AND date < DATE(#ENDDATE)
LIMIT 10
I'm getting an error directly from the editor with this message:
> Error BigQuery: No matching signature for function DATE for argument types: INT64. Supported signatures: DATE(TIMESTAMP, [STRING]); DATE(DATETIME); DATE(INT64, INT64, INT64) at [8:14]
As far as I can understand, the "date" cells are retrieved as a number, so the direct parse is not working. After a couple of tests, I understood the that given int value is the number I can obtain change cell format to "number".
If you convert cell value from DATE to NUMBER you get this value:
01/05/2019 -> 43.586
31/05/2019 -> 43.616
What is this number? It is not milliseconds, it increases by 1 every next day. In order to create the proper query that can parse this int, I need to understand what is this int (of course I can handle the cell as "text" and writing the timestamp value directly, but I would prefer to have the native date format so I can use the built-in calendar.
My consideration (with simple math) is that this number refers to a number of days since 30/12/1899, but it is very odd (also, every date BEFORE this days is always 0), so I'm asking you directly how to handle this value. Basing on my understanding of when the number counter starts (30/12/1899), I created this query which add the number retrieved from the cell:
SELECT *
FROM `bigquery-public-data.utility_eu.date_greg`
WHERE
date >= DATE_ADD(DATE("1899-12-30"), INTERVAL #DATAINIZIO DAY)
AND date <= DATE_ADD(DATE("1899-12-30"), INTERVAL #DATAFINE DAY)
It is working... but I think I'm doing a workaround that is not the proper way of doing this.
Also, is there any full documentation related to this BigQuery connection provided by Spreadsheet? Besides presentation in 1 I'm unable to find any specific documentation.
Spreadsheets (Google, Excel, ...) store the dates as days passed since a starting date with a fractional day representing time.
From here: "Excel stores dates and times as a number representing the number of days since 1900-Jan-0, plus a fractional portion of a 24 hour day: ddddd.tttttt . This is called a serial date, or serial date-time."
Now, you have to ways to filter by date on your Query:
In the query, you can use DATE_ADD to add your number of days (cell value) to the base date. (Carefull, DATE_ADD takes INT, and the date value is float so needs prior casting).
(preferred) on your spreadsheet you use TEXT(cell, "yyyy-mm-dd") so you can then use DATE() in the BigQuery query.
I use the second method as, though you need that extra cell (unless you directly store the date as YYYY-MM-DD; keeps the query cleaner than having a cast and date_add in there. Also would save you from the "1904 problem" explained in the link above.
What is this number? It is not milliseconds, it increases by 1 every next day.
This is so called serial number which represent number of days since "very beginning"
Google's Spreadsheet date calendar starts from 1900-01-01 - which is treated as a "very beginning"
In order to create the proper query that can parse this int, I need to understand what is this int
Armed with above info you can adjust you dates calculation to be in sync with what BigQuery expects
You mentioned that your fields are already in Date format, maybe you are doing an extra parsing in your query.
Try to do it without the DATE functions.
Also, I found this other doc, not merely related to connection, but might be helpful: Getting info from Spreadsheets with BigQuery.

SSRS Preset or Custom Date Selection on Report

I currently have a report with the ability to select a start and end date. I was curious if you could make have both preset and the option for a custom selection
Selection:
Current Week, or
Previous Week, or
Custom Date Range.
Thanks,
Take a look at cascading parameters.
The link above seems to focus more on getting your cascading parameter values from a query, but you probably don't want that for a date - as far as I am aware, setting Available Values for a date parameter limits you to a dropdown list of dates, instead of the calendar which is generally easier to use. It is still a good background on how cascading parameters work though.
To do this with expressions for the default start/end date, you would basically want the first parameter to be a choice between "Current Week", "Previous Week", and "Custom Date Range". You would display those labels to the user, but the values can be whatever you want - for my test I just used 1, 2, and 3.
Then, you would set up 2 more parameters, one for the start date and one for the end date. Make sure the data type is Date. You will want to set up default values for these based on the value of the first parameter. I would do this with an expression such as the expression below for the start date. You also may need to modify this a bit depending on how you define the week - is the "Current Week" just the previous 7 days, or is it the latest Monday through today, or something else, etc.
=Switch(
Parameters!FirstParam.Value = 1, DateAdd("d", -7, Today()),
Parameters!FirstParam.Value = 2, DateAdd("d", -14, Today())
)
In this case, you don't even need to account for the 3rd option, because if the user wants a custom date range then you do not want the start and end date to fill in with any default values. You would need a similar expression for the default end date as well.
Since you want the user to be able to enter a custom range as well if they were to select the third option, you do not want to fill in the Available Values for the start/end date parameters, as the user would then not be able to select any date (at least as far as I am aware - if there is a workaround to that, I would love to see it, as that would be something I would like to use myself).
A possible downside to this approach is that if the user begins by selecting Current Week and then changes their mind to Previous Week, the start/end dates will not change to the Previous Week. You can read more about why this happens here, but essentially: since the values that are already filled in after selecting Current Week are still valid (they are dates, which is the only criteria for those parameters since no available values are set up), they will not refresh after changing the selection. The fix for this is to define the Available Values, but as mentioned above, this will then stop the user from entering a custom date range.

Number of days between past date and current date in Google spreadsheet

I want to calculate the number of days passed between past date and a current date. My past date is in the format dd/mm/yyyy format. I have used below mentioned formulas but giving the proper output.
=DAYS360(A2,TODAY())
=MINUS(D2,TODAY())
In the above formula A2 = 4/12/2012 (dd/mm/yyyy) and I am not sure whether TODAY returns in dd/mm/yyyy format or not. I have tried using 123 button on the tool bar, but no luck.
The following seemed to work well for me:
=DATEDIF(B2, Today(), "D")
DAYS360 does not calculate what you want, i.e. the number of days passed between the two dates – see the end of this post for details.
MINUS() should work fine, just not how you tried but the other way round:
=MINUS(TODAY(),D2)
You may also use simple subtraction (-):
=TODAY()-D2
I made an updated copy of #DrCord’s sample spreadsheet to illustrate this.
Are you SURE you want DAYS360? That is a specialized function used in the
financial sector to simplify calculations for bonds. It assumes a 360 day
year, with 12 months of 30 days each. If you really want actual days, you'll
lose 6 days each year.
[source]
Since this is the top Google answer for this, and it was way easier than I expected, here is the simple answer. Just subtract date1 from date2.
If this is your spreadsheet dates
A B
1 10/11/2017 12/1/2017
=(B1)-(A1)
results in 51, which is the number of days between a past date and a current date in Google spreadsheet
As long as it is a date format Google Sheets recognizes, you can directly subtract them and it will be correct.
To do it for a current date, just use the =TODAY() function.
=TODAY()-A1
While today works great, you can't use a date directly in the formula, you should referencing a cell that contains a date.
=(12/1/2017)-(10/1/2017) results in 0.0009915716411, not 61.
I used your idea, and found the difference and then just divided by 365 days. Worked a treat.
=MINUS(F2,TODAY())/365
Then I shifted my cell properties to not display decimals.
If you are using the two formulas at the same time, it will not work...
Here is a simple spreadsheet with it working:
https://docs.google.com/spreadsheet/ccc?key=0AiOy0YDBXjt4dDJSQWg1Qlp6TEw5SzNqZENGOWgwbGc
If you are still getting problems I would need to know what type of erroneous result you are getting.
Today() returns a numeric integer value: Returns the current computer system date. The value is updated when your document recalculates. TODAY is a function without arguments.
The following worked for me. Kindly note that TODAY() must NOT be the first argument in the function otherwise it will not work.
=DATEDIF( W2, TODAY(), "d")
Today() does return value in DATE format.
Select your "Days left field" and paste this formula in the field
=DAYS360(today(),C2)
Go to Format > Number > More formats >Custom number format and select the number with no decimal numbers.
I tested, it works, at least in new version of Sheets, March 2015.

Jasperreports time series chart timePeriod Expression

I have dataset with 00:00:00,00:00:15...
how to set it to be the timePeriod Expression to show one day's time from 00:00:00 to 23:59:59
i put (Date)new SimpleDateFormat("HH:mm").parse($F{time}) into the timePeriod Expression
but the chart just show one time point
If you don't have gaps you can use Line chart like DeGriz's link to Tarnschaf's answer.
If you may have gaps or would like to summarise the data ensure you use <timeSeriesDatasettimePeriod="Second"> or perhaps timePeriod="Minute" otherwise it tends to default to something large like a year, hence one data point.
THE JASPERREPORTS ULTIMATE GUIDE: Time Period Expression
This expression returns a java.util.Date value from which the engine will extract the
corresponding time period depending on the value set for the timePeriod attribute
mentioned earlier in the Time Series dataset. For instance, if the chart is about yearly
data, the engine will extract only the year from the date value, or if you are gathering
monthly data, the engine will use only the month value from the date object returned by
this expression.
I think you may also be asking to set the Min and Max for the axis to exactly one day, for this I believe you can use <domainAxisMinValueExpression> and <domainAxisMaxValueExpression>