Showing posts with label Google Spreadsheet Formulas. Show all posts
Showing posts with label Google Spreadsheet Formulas. Show all posts

Tuesday, September 18, 2012

Google Spreadsheet ImportHtml auto update or refresh

Question:

I'm using the =ImportHtml function to get some data from an HTML table.

It works okay, but I need it to refresh. The HTML data will change periodically, so I need the spreadsheet to periodically check to see if the data have been updated.
Right now it seems to be pretty static, and I can't find a setting or anything to make it check for new data.
I've searched through some forums and can't find an answer or a workaround.
Please help!
(I'm a programmer, so feel free to get as techy as needed. And if anyone knows of anything in the Java API that can help me, please advise)


Solution:

Following is the work around to get the auto-refreshed values (results) from ImportHtml fomula:

You have to pass the parameters at the end of the URL (these parameters are meaning less, adding these parameters to URL will not change your results, and these parameters are used to only change the URL again and again so that we can get the refreshed values)

For example:

If you are having the following URL in ImportHtml formula:
=ImportHtml("http://www.nasdaq.com","table",4)

Then change it to:
=ImportHtml("http://www.nasdaq.com/?"& minute(now()),"table",4)

The above formula will update your imported content from html every minute.
But in this case also chances are that you will get the same table again after an hour, this is because suppose minute(now()) returns 6 as value, so it is going to return 6 after an hour hour, so chances are you will get 60 times updated value and then again you will get same results.

So to avoid it you can try following formula:

=ImportHtml("http://www.nasdaq.com/?"& year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()),"table",4)
The above formula will give you updated results every minute.


And if you want updated result every second then change it to:

=ImportHtml("http://www.nasdaq.com/?"& year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()) & second(now()),"table",4)


Note:
If you don't see auto update then just press "delete" key on any empty cell this will make your spreadsheet refresh this formula and it will work. (And if you want to auto update (refresh) then you can code a script for that)


I hope the above solution helps you.

Sunday, August 19, 2012

Google Spreadsheet calculate SUM values according to a criteria

Let's see a example of it:


I'm trying to have my spreadsheet that calculates SUM values according to the person's name selected in a drop down list.  I have names in a drop down list in column A. With days totals in column B and Month totals in column C. when an person makes a entry, they select their name and add the day and month amounts. 

I need to have each person have their days totals SUM up in one cell and month totals Sum up in another cell.


So in the above table we want to get the values in the range F3:G6


So by putting following formulas at the mentioned cells in the spreadsheet we will get the results:

F3 =sumproduct(filter(B2:B,A2:A=E3))
F4 =sumproduct(filter(B3:B,A3:A=E4))
F5 =sumproduct(filter(B4:B,A4:A=E5))
G3 =sumproduct(filter(C2:C,A2:A=E3))
G4 =sumproduct(filter(C3:C,A3:A=E4))
G5 =sumproduct(filter(C3:C,A3:A=E5))

By inserting these formulas we will get the results as shown below in the screenshot:


I hope this makes you understand, the functioning of "sumproduct" and "filter" funtions.

Saturday, August 18, 2012

How to count how many times a name appears on one sheet

If you are wondering how to count a specific value (may be a number or a name or a date or any content of a cell) from a specific range of one sheet to another sheet of a spreadsheet then here is the formula.

Suppose you have a Sheet named "Summary" and you want to count how many times "John" appears in a range A4:S34 in the Sheet named "SignIn" (which is in the same spreasheet), then you can count it with the help of function "COUNTIF". Here is the formula:


=COUNTIF(SignIn!A4:S34,"John")

Here, the above formula will return the number of times "John" appearing in Sheet named "SignIn".


Friday, August 17, 2012

Formula to check a criteria in a specific range.

Suppose you want to get "FAIL" in a cell if a certain criteria is met in another range of cells. So in the table below, J4 would return the text FAIL, and J5 would return the text PASS.



Now, paste this formula in cell J4
=if(COUNTIF(C4:I4,"X")=0,"PASS","FAIL") 

And this formula in cell J5
=if(COUNTIF(C5:I5,"X")=0,"PASS","FAIL") 

Here function "COUNTIF" will search for the criteria "X" and if this criteria returns 0, it means student has passed all areas and J5 will displays "PASS".

I hope the above example will make you understand how to use the formula "CountIf" in Google Spreadsheets.


Importing a Range of one spreadsheet to another spreadsheet

If you want to refer a cell to a Spreadsheet from different Spreadsheet, then here is the formula which will do your job:


=ImportRange("0AmMTqpzD9YRndEZTTV9XNWpEaGM1RHJqY0ZIY3RTVnc","Sheet1!A1:A1")


ImportRange is a function which is extremely helpful when you have to call in the data from other spreadsheet. It is used to synchronize the master spreadsheet and the spreadsheets from which data is fetched.


Note:

Here "0AmMTqpzD9YRndEZTTV9XNWpEaGM1RHJqY0ZIY3RTVnc" is the key of the Spreadheet, which you can find in the URL.



And if you want to import range "A1:C3" of Sheet "my Sheet" from one Spreadsheet to another one then here is the formula for that:


=ImportRange("0AmMTqpzD9YRndEZTTV9XNWpEaGM1RHJqY0ZIY3RTVnc","my Sheet!A1:C3")


I hope this post helps you to understand the basics concept of ImportRange function.