Google Sheets: NOW Formula Populating Numeric Value Only - google-sheets

I'm trying to add a NOW statement in my IF formula. Its working but populating numeric values only, see formula below:
=IF(D3="","",NOW())&"-Login Details and Tablet have been sent to partner"
Result: 44005.4947026389-Login Details and Tablet have been sent to partner

The number you're getting refers to the quantity of days passed since December 30, 1899. When you concatenate this date with other content, the cell is not being interpreted as a date, so the date is not getting formatted according to your preferences.
To format this date, you could use TEXT (check the Notes to see the possible formatting options for this). See, for example, this:
=IF(D3="","",TEXT(NOW(),"yyyy-mm-dd_hh:mm:ss"))&"-Login Details and Tablet have been sent to partner"
Reference:
TEXT

Related

Google Sheet-Date validation in specific format

how to use specific date formats in data validation in Google Sheets.
I set this date format in google sheet dd-mmm-yyyy (09-Jan-2023) but the user enters a different date format in the sheet so im want to use data validation for this the user must enter data in specific format dd-mmm-yyyy
i want that when user enter data in different format its auto rejects entry.
try:
=REGEXMATCH(A1&""; "\d{2}-.{3}-\d{4}")
or:
=REGEXMATCH(A1; "\d{2}-.[A-z]{3}-\d{4}")
If you previously set the date format in the range you want, then no matter in which way the date is inserted then it will be displayed as you wish. Specially with mmm format you'll be always at risk that they can mess with how the month is supposed to be written, I think it's preferably for them to insert the number and you choose how it is displayed

How to i change the date time format on Google Sheets?

I am working on a datasheet on Google sheets and I am trying to change values in column (D) to date time format, so I went to Format<number<date time. But only a few values are getting converted and the rest remain the same. Please see below-
Screenshot of column D
The values aligned on right are converted and the left ones aren't. I even tried paint format, trim white spaces but it didnt work. Please suggest a way on how to resolve this error. Also, there are 49623 values in column D.
thank you
Your spreadsheet is set to a locale that uses the mm/dd/yyyy date format, while your data is using the dd/mm/yyyy date format. That means that the dates where the day of the month is less than or equal to 12 will get converted to dates incorrectly, and the rest of the data will remain as text strings.
To make it work, choose File > Settings > Locale and choose a locale that matches your data, then repaste the data to convert it correctly.
The "49623 values" are dateserials that can be converted to dates by formatting them in a date format. See this answer for an explanation of how date and time values work in spreadsheets.

Exact same formula producing two different results depending on cell in google sheets

I'm making a calendar heat map of my org's sessions per day. There might be easier ways to do it, but I have one sheet for a calendar, another listing every single session by day, and the heat map sheet that looks at the equivalent calendar cell and counts how many sessions match that date. Conditional formatting changes the colour of the date cell depending on the number. Screenshot of sheet setup. (sorry, can't imbed images)
Each cell on my heat map matches a cell on the calendar sheet, so each heat map cell contains:
=countif(Sessions!$A:$A,'Calendar 2021'!B5)
with the cell address changing for each date.
It all looked good until one date cell returned the wrong count for that date. When I checked the formula for that date, I found that it did return the right count - when I copied it to a different cell.
It's the exact same formula in each cell :
=countif(Sessions!$A:$A,'Calendar 2021'!C23)
but in columns A-L, it returns '3', and after column M it returns '4' (the correct result).
screenshot of different results
Any idea what's causing that?
If it's useful to have a look yourself, here's a version with the same problem (stripped of all data but the dates): https://docs.google.com/spreadsheets/d/16xP_a_KgeIoqomdsk3kMUDuV2GyIVMoNoOusvfWJdNU/edit?usp=sharing
You have different formatting applied to the various cells: none of which are correct for your use, by the way.
In the cells producing a result of 3, you have formatting set to "d". This means you're requesting that the format show the day of the week instead of the underlying number (meaning that the only possible returns for this formatting are the numbers 1 - 7). Since your underlying correct number is 4, the d formatting assumes that 4 is a raw date. The date-time origin in Sheets is December 30, 1899, which corresponds to the number 0. So 4 would translate to January 3, 1900. And the day of the week (d) of that date was a Tuesday, which in Sheets, is day 3 of the week counting from Sunday ... hence your formatted return of 3.
In the cells returning 4, it is only a happy accident that they are; because you've got the formatting for those set to return a date-time. As it so happens, the raw number 4 is the same as the 4th day from the origin date in Sheets; so you happen to be getting a formatted return of 4.
You should be selecting the entire range A:R in your heat map sheet and setting the formatting to simply '0', which means "the original raw number." Setting the formatting this way will not affect text, only numbers.
I should note that your formatting and data types in your sample sheet are all over the place. Some of your numbers are generated by formula. Some are raw dates. So when you set the whole thing to formatting 0, many of your cells are going to show numbers in the 40000 range, corresponding to the number of elapsed days for the underlying date as marked from December 30, 1899. You'll need to be sure that every applicable cell in your heat map sheet contains a formula that returns the COUNTIF, not dates.

How to Count Timestamp on Google Spreadsheets?

My responses are timestamped as soon as anyone submits a survey. I wanted to count those timestamp monthwise.
URL - https://docs.google.com/spreadsheet/ccc?key=0AkpZp6MVqYv1dE5SZjJIODB1WF9nZDR6b1ZJZjFPenc&usp=sharing
I wanted to find out number of positive responses for a particular question (lets say Q1) for a particular month (lets say May)
Column G is not founded out based on the timestamp of Q1, I had asked the user the month, but that's not the correct way to do so, so I have stopped asking the user to enter the month.
First you have to overcome the fact that the timestamp isn't compatible with googles date format. No biggie,... luckily it looks like you have a fixed format ie DD/MM/YYYY. So you can use the LEFT and RIGHT formulas like so =right(left(a2,5),2) This will give you the month in text, ie 05.
Great.
Now for the harder stuff. If you have the newer google spreadsheets, you can simply use countifs to the effect of:
=countifs(arrayformula(right(left(A$2:A,5),2)),"=05",B$2:B,"=Positive")
For each month, replace the "=05" with the the date number you want. You could also make a month lookup chart for all months and questions so that you don't have to modify the formula for each month and quesiton. For this you replace the "=05" with =[cell number containing month number as text] (NOTE: for making a lookup key, you will have to pay close attention to the fact that you are getting TEXT in the formula above vice a number. There is a difference and they are not compatible as-is.)
Let's say you don't have the new google spreadsheets. Then you can use the old sumproduct() and if(). Yes, it is old. See the following:
=sumproduct(arrayformula(if(right(left(A$2:A,5),2)="05",1,0)),arrayformula(if(B$2:B="Positive",1,0)))
Note in both of these, you need to use arrayformula to convert the column with the timestamp into something useable. If you want to make this part easier by removing the parseing functions (LEFT() and RIGHT()) you need to change the timestamp format to be MM/DD/YYYY. Then you can plug in the the MONTH(DATE) formula and it will be done.
Then make a master sheet like so (note my formula has a "'" in it to make it visible for purposes of demonstration, you should remove it.):
Careful inspection might note that the count is wrong. That is because when I imported your timestamps, times like "02/06/2014 ..." were interpreted to mean "February 06" because of google's auto-formatting. In your sheet you will get the correct count using this formula, because of the way your timestamp is auto-populated.
HINT: To make the month a text you need to enter ="05" in the Month column
Please let me know how you make out.

On Google Spreadsheet how can you query 'GoogleFinance' for a past exchange rate?

I'd like to know if it is possible to query a past exchange rate on Google Spreadsheet.
For example; using formula =GoogleFinance("CURRENCY:USDEUR") will return the USD/EUR rate at this present moment. How can you retrieve a historic rate?
In order to retrieve the historical rate, you have to use the following formula:
=GoogleFinance("eurusd","price",today()-1,today())
where today()-1, today() is the desired time interval, which can be explicitly defined as the static pair of dates, or implicitly, as the dynamically calculated values, like in the example above. This expression returns a two-column array of the dates and close values. It is important to care about the suitable cell format (date/number), otherwise your data will be broken.
If you want to get the pure row with the date and currency exchange rate without column headers, wrap your formula with the INDEX() function:
=INDEX(GoogleFinance("eurusd","price",today()-1,today()),2,)
To retrieve the exchange rate value only, define the column number parameter:
=INDEX(GoogleFinance("eurusd","price",today()-1,today()),2,2)
To get today's currency exchange rates in Google Docs/Spreadsheet from Google Finance:
=GoogleFinance("eurusd","price",today())
A shorter way to get today's rates:
=GoogleFinance("currency:usdeur")
P.S. There is also the way to get live currency exchange rate in Microsoft Excel.
Try,
=GoogleFinance("usdeur","price",date(2013,12,1),date(2013,12,16))
Make sure that the dates are as per your spreadsheet settings.
Edit as comment, changed date for capturing single day data:-
Only with headers:
=INDEX(GoogleFinance("usdeur","price",date(2013,12,3),date(2013,12,4)),,2)
without headers:
=FILTER(INDEX(GoogleFinance("usdeur","price",date(2013,12,3),date(2013,12,4)),,2),INDEX(GoogleFinance("usdeur","price",date(2013,12,3),date(2013,12,4)),,2)<>"Close")
The instructions for all related to googlefinance are in here: https://support.google.com/docs/answer/3093281
Remember the actual Google Spreadsheets Formulas use semicolon (;) instead of comma (,).
Once made the replacement on some examples would look like this:
For a 30 day INDEX of USD vs EUR you should use (note that in the case of currencies they go together in the same first variable):
=INDEX(GoogleFinance(USDEUR;"price";today()-30;today());2;2)
TIP: You can get the graph over the entire size of the cell by simply changing INDEX for SPARKLINE, like this:
=SPARKLINE(GoogleFinance(USDEUR;"price";today()-30;today());2;2)
Vasim's answer is excellent, however notice if you want the exchange date on that day only, you can omit the range and just specify the day such as the following
=FILTER(INDEX(GoogleFinance("usdeur","price",today()),,2),INDEX(GoogleFinance("usdeur","price",today()),,2)<>"Close")
You may notice that GOOGLEFINANCE will return N/A for some dates, this is because the date is a day off (usually a weekend), what you can do is to get the last working from the specified date, e.g. Jun 21st 2015 is Sunday, so you should request the rate for Jun 19th (Friday), you can do this via WORKDAY function as was suggested here:
WORKDAY("6/21/2015"+1,-1)
So, the resulting formula will look something like that:
INDEX(GoogleFinance("CURRENCY:USDRUB", "price", WORKDAY("6/21/2015"+1,-1),1),2,2)
Additionally, you want to get the exchange rates for future dates you can additionally check if the date is in the future and if so, just use the today date:
WORKDAY(IF("6/21/2099">TODAY(),TODAY(),"6/21/2099")+1,-1)
For bigger spreadsheets, Google Sheets limitations usually will show randomly the following error:
Error Function INDEX parameter 2 value is 2. Valid values are between
0 and 1 inclusive.
Even modifying Index() and GoogleFinance() following the expected parameters GOOGLEFINANCE(ticker, [attribute], [start_date], [end_date|num_days], [interval]) the error will continue.
A workaround is to copy smaller parts into new spreadsheets but often it will fail.
As an alternative, I used ImportXML as web scraper for x-rates historical currency exchange data.
=index(IMPORTXML("https://www.x-rates.com/historical/?from="&N2&"&amount="&K2&"&date="&YEAR(B2)&"-"&TEXT(B2,"mm")&"-"&TEXT(B2,"dd")&"","//td[#class='rtRates']"),1)
I'm assuming column B are dates, K is for amounts and N for currencies.
Randomly it also will fail for a 2000+ rows spreadsheet but overall for my requirement, it worked too much better than GoogleFinance()
ImportXML examples
The ImportXML Guide for Google Docs from beginner to advanced
Other option is using the CurrencyConverter function from this Google Sheets add-on.
It is fast and and has simple syntax. For example,
=CurrencyConverter(100, "USD", "EUR", "2/28/2020")
returns 91.09957183

Resources