How to show fusion table rows that ST_INTERSECTS multiple possible locations in a single layer? - google-fusion-tables

I have a pretty routine fusion table that contains rows of data where each row has a location column that contains a polygon (or multiple polygons in a multigeometry). I use this fusion table data to draw polygons on a google map object within a web page using google.maps.FusionTablesLayer. Creating a query that uses a single location as a CIRCLE with a small radius within an ST_INTERSECTS is a trivial exercise and works perfectly.
However, I now need to be able to query all rows within the fusion table that intersect multiple possible locations (essentially the results of a geocode of a search term). Each row need only intersect at least one of the locations to be included in the result set.
Things I have already tried and or considered ...
1) Multiple layers don't work as I would be limited to at most 5 locations and only one of them can be styled the way I need.
2) Building a LatLngBounds with each location then doing an ST_INTERSECTS on the RECTANGLE formed by the bounds. As is obvious once you do it, this shows you all polygons that are between two distant locations, but don't actual contain the locations (because we're now looking for polygons intersecting a large rectangle around the two points) - something I don't want.
3) You can't do "ST_INTERSECTS(GEOMETRY, CIRCLE(location1, 1)) OR ST_INTERSECTS(GEOMETRY, CIRCLE(location2, 1))" <= This would be the perfect solution if it worked!
4) You can't do an SQL union with a fusion table query.
5) You can't do multiple SQL selects within a single fusion table query.
Is there any way I can do this within a single fusion table layer?
Thanks in advance for any input!

I'm afraid the only possible solution here may be to request first the rows(a unique column with an ID, but not the internally stored rowId ), single requests for each location.
When you got all the results, build the query for the FTlayer based on the returned ID's , a'la:
where: "columnWithIds IN('collected','ids','from','the','previous','requests')"
If this will be applicable in your situation will depend on
the number of locations(limits for webService-requests)
the number of returned rows(browserLimit for URL-length)

Related

How to generate a distribution based bar chart on row_numbers

I have a SQL query that acts as a data source in my tableau desktop:
SELECT
row_number() over (order by sales) as rn,
article_number,
country,
SUM(sold_items) as si,
SUM(sales) as sales
FROM data.sales
WHERE sales.order_date between '2021-01-01' and '2021-12-31'
GROUP BY 2, 3
On tableau I dragged rn to column and sales to row to generate a bar chart. The following is the output:
I want to convert this into a 0-100% distribution chart so that I can get the following result:
How can I achieve this? Also, I want the user to filter by country level so even if the # of records increase or decrease, the distribution should always be consistent with the filtered data.
You can do this with nested table calcs.
For example, the following uses the Superstore sample data set, and then first computes a running total of SUM(Sales) per day, then converts that to a percent of total. Notice the edit table calc dialog box - applying two back to back calculations in this case.
The x-axis in this example is Order-Date, and in your question, the the x-axis is a percentage somehow - so its not exactly what you requested but still shows that table calcs are an easy way to do these types of operations.
Also, realize you can just connect to the sales table directly, the custom sql isn’t adding any value, and in fact can defeat query optimizations that Tableau normally makes.
The tableau help docs explains table calculations. Pay attention to the discussion on partitioning and addressing.

Extract Last Value as Metric from Table Calculation in Tableau?

I have raw data in Tableau that looks like:
Month,Total
2021-08,17
2021-09,34
2021-10,41
2021-11,26
2021-12,6
And by using the following calculation
RUNNING_SUM(
COUNTD(IF [Inserted At]>=[Parameters].[Start Date]
AND [Inserted At]<=[End Date]
THEN [Id] ELSE NULL END
))
/
LOOKUP(RUNNING_SUM(
COUNTD(IF [Inserted At]>=[Parameters].[Start Date]
AND [Inserted At]<=[End Date]
THEN [Id] ELSE NULL END
)),-1)*100-100
I get
Month,My_Calc
2021-08,NULL
2021-09,200
2021-10,80.4
2021-11,28.3
2021-12,5.1
And all I really want is 5.1 (last monthly value) as one big metric (% Month-Over-Month Growth).
How can I accomplish this?
I'm relatively new to Tableau and don't know how to use calculated fields in conjunction with the date groupings aspect to express I want to calculate month-over-month growth. I've tried the native year-over-year growth running total table calculation but that didn't end with the same result since I think my calculation method is different.
First a brief table calc intro, and then the answer at the end.
Most calculations in Tableau are actually performed by the data source (e.g. database server), and the results are then returned to Tableau (i.e. the client) for presentation. This separation of responsibilities allows high performance, even when facing very large data sets.
By contrast, table calculations operate on the table of query results that were returned from the server. They are executed late in the order of operations pipeline. That is why table calcs operate on aggregated data -- i.e. you have to ask for WINDOW_SUM(SUM([Sales)) and not WINDOW_SUM([Sales])
Table calcs give you an opportunity to make final passes of calculations over the query results returned from the data source before presentation to the user. You can for instance calculate a running total or make the visualization layout dynamically depend in part on the contents of the query results. This flexibility comes at a cost, the calculation is only one part of defining a table calc. You also have to specify how to apply the calculation to the table of summary results, known as partitioning and addressing. The Tableau on-line help has a useful definition of partitioning and addressing.
Essentially, table calcs are applied to blocks of summary data at a time, aka vectors or windows. Partitioning is how you tell Tableau how you wish to break up the summary query results into windows for purposes of applying your table calc. Addressing is how you specify the order in which you wish to traverse those partitions. Addressing is important for some table calcs, such as RUNNING_SUM, and unimportant for others, such as WINDOW_SUM.
Besides understanding partitioning and addressing very well, it is also helpful to learn about the functions INDEX(), SIZE(), FIRST(), LAST(), WINDOW_SUM(), LOOKUP() and (eventually) PREVIOUS_VALUE() to really understand table calcs. If you really understand them, you'll be able to implement all of these functions using just two of them as the fundamental ones.
Finally, to partially address your question:
You can use the boolean formula LAST() = 0 to tell if you are at the last value of your partition. If you use that formula as a filter, you can hide all the other values. You'll have to get partitioning and addressing specified correctly. You would essentially be fetching a batch of data from your server, using it in calculations on the client side, but only displaying part of it. This can be a bit brittle depending on which fields are on which shelves, but it can work.
Normally, it is more efficient to use a calculation that can be performed server-side, such as LOD calc, if that allows you to avoid fetching data only for client side calculations. But if the data is already fetched for another purpose, or if the calculation requires table calc features, such as the ability to depend on the order of the values, then table calcs are a good tool.
However you do it, the % month-to-month change from 2021.11 (a value of 26) to the value for 2021.12 (a value of 6) is not 5.1%.
It's (( 6 - 26 ) / 26) * 100 = -76.9 %
OK, starting from scratch, this works for me: ( I don't know how to get exactly the table format I want without using ShowMe and Flip, but it works. Anyone else? )
drag Date to rows, change it to combined Month(Date)
drag sales to column shelf
in showme select TEXT-TABLES
flip rows for columns using tool bar
that gets a table like the one you show above
Drag Sales to color (This is a trick to simply hold it for a minute ),
click the down-arrow on the new SALES pill in the mark card,
select "Add a table calculation",
select Running Total, of SUM, compute using Table(down), but don't close this popup window yet.
click Add Secondary Calculation checkbox at the bottom
select Percent Different From
compute using table down
relative to Previous
Accept your work by closing the popup (x).
NOW, change the new pill in the mark card from color to text
you can see the 5.1% at the bottom. Almost done.
Reformat again by clicking table in ShowMe
and flipping axes.
click the sales column header and hide it
create a new calculated field
label 'rows-from-bottom'
formula = last()
close the popup
drag the new pill rows-from-bottom to the filters shelf
select range 0 to 0
close the popup.
Done.
For the next two weeks you can see the finished workbook here
https://public.tableau.com/app/profile/wade.schuette/viz/month-to-month/hiderows?publish=yes

Is it possible to create a choropleth map solely from a set of long/lat coordinates?

I'd like to visualize a number of points on a map. Unfortunately, there is no consistent address associated with each one. I've used Google Fusion tables to get a rough read on where the points are, and am relatively satisfied with the approximate locations of most points (sometimes Google figures out where they're located based on a landmark, sometimes based on an intersection provided, sometimes by street address, etc.).
My goal, then, is to create a choropleth map of a city (NYC, in this case), showing the number of points located in each neighbourhood. Is it possible to do this by somehow counting the number of points that fall within each neighbourhood?
I suspect that if fusion tables give me a passable visual, I may be able to use google's geocoding service in the same manner to figure out the number of points in each area, and use this to then build a choropleth (not a heat map — I'm after some level of interaction, like tooltips over each neighbourhood).
Is there any way to do this, or am I way, way off?

Fusion tables OR is not supported [duplicate]

According to https://developers.google.com/fusiontables/docs/developers_reference OR operations are not allowed as part of filter conditions. So I'm trying to come up with a creative way to solve the following:
I have a fusion table backed google map with hundreds of places and want to filter it to only places that have 'tags' or a 'title' containing a search parameter.
Ideally I could just use the following as my filter condition:
tags CONTAINS IGNORING CASE 'searchterm' OR title CONTAINS IGNORING CASE 'searchterm'
But the fusion table API simply doesn't allow it. So what to do? Make 2 separate queries, then filter out the duplicates? That means I can't use the nice FusionTablesLayer pre-rendered tile functionality.
What would you do?
A possible answer is to pre-render the data within the table. Essentially add another column which is an aggregate of tags and title. Then I only need to query the one 'tags_or_titles' column. Of course this means more data munging beforehand when I export the data into the fusion table and doesn't feel so nice and clean...
How about adding a column to your table called "Show_In_Results",
then running two separate queries to update that column for each row of data based on whether the search term is found in the specific column or not.
UPDATE 'table_id'
SET Show_In_Results = 1
UPDATE 'table_id'
SET Show_In_Results = 1
WHERE tags CONTAINS IGNORING CASE 'searchterm'
UPDATE 'table_id'
SET Show_In_Results = 1
WHERE title CONTAINS IGNORING CASE 'searchterm' and Show_In_Results <> 1
Then when you render your map layer:
SELECT 'columns' FROM 'table_id' WHERE Show_In_Results = 1

Query or filter on Fusion Tables?

this a question from a very inexperienced user.
I have a table with electoral results, with this format:
I have merged this table with city shapes and can do a map visualization according to one of the columns.
My problem comes when I want to do filters and queries. I am quite puzzled.
I know how to activate and deactivate layers from an html document, calling (showing and hiding) different fusion tables.
What I want to try now is using a sole fusion table for different ways to show the data. I don't know if this is possible.
For example, possible queries to show on different maps called from a html page:
show only rows with type (column H) 'rural' (filter?)
fill polygons with colours according to the greater value among column B, D and F (if value for party1_2012 is > than party 2 2012 and > than party 3 2012, polygon colour is blue; if party 2 wins, fill is red...)
fill polygons with colours according to the difference between 2 columns (i.e. 2010 and 2012 results)
map combining option 1 (when showing only rural city), apply option 3 (show a colour according the difference between 2 columns)
Inspired by John Keefe's post Making AP Election Data Easy with Fusion Tables, tried to play with data, but no luck. I'm too inexperienced. Is it the way to go generate csv and call them from a webpage? Can I just generate the maps on Fusion Tables and obtain a url to call the queried mapfrom a webpage?
I appreciate suggestions or ways to go.
Thanks in anticipation!
Frans

Resources