How to edit a query in Apache Superset? - data-visualization

I'd like to change the query so that the metrics / labels are different. So instead of the chart saying "sum_sum_girls", it would say something like "Total Girls" instead.
Current query is as follows:
SELECT state AS state,
SUM(sum_girls) AS sum__sum_girls
FROM birth_names
WHERE ds >= '1918-05-11 00:00:00.000000'
AND ds <= '2018-05-11 18:03:20.000000'
AND state NOT IN ('other')
GROUP BY state
ORDER BY sum__sum_girls DESC
LIMIT 50000
OFFSET 0;`enter code here`
I'd like to change it so it says
SELECT state AS state,
SUM(sum_girls) AS Total_Girls
FROM birth_names
WHERE ds >= '1918-05-11 00:00:00.000000'
AND ds <= '2018-05-11 18:03:20.000000'
AND state NOT IN ('other')
GROUP BY state
ORDER BY sum__sum_girls DESC
LIMIT 50000
OFFSET 0;
Any advice? Tried Googling to no avail. I'm used to being able to create easy custom SQL queries in Tableau.

You should be able to create custom queries by navigating to 'SQL Lab' > 'SQL Editor'.
You should then be able to create queries and re-use them in your graph.
See "Creating Datasources Using SQL Lab" on https://duperset.com/getting_started

Not sure if this is what you are looking for, but I'm gonna try.
For a chart you can define a Verbose Name for any metric you have. This is going to be the name displayed as a legend to the chart.
To do so, please go to the Datasuource(sometimes it is also called Table) you use for the chart and there to the List Metrics tab.

Go to Edit Datasource and in tab Metrics define metrics and its labels which will be shown in the chart.
Another approach is to define it directly in chart like in the picture below:

Related

how to set an image link into dynamic list correctly in oracle apex?

Good day, I have created a dynamic list where I passed the image link as per previous posts here.
However, the card will not display the image and the query is:
SELECT NULL,
COURSE_NAME label,
'f?p=&APP_ID.:502:'||:APP_SESSION as target,
'YES' is_current,
'#APP_IMAGES#abcd.jpg' IMG_PATH,
'width="20" height="20"' IMAGE_ATTRIBUTE,
COURSE_NAME image_alt
FROM LS_COURSES
ORDER BY COURSE_NAME
Use the below alias name for the columns in your SQL
select CARD_PRIMARY_KEY,
CARD_TITLE,
CARD_SUBTITLE,
CARD_BODY,
CARD_SECONDARY_BODY,
CARD_ICON,
CARD_BADGE,
CARD_IMAGE
from YOUR_TABLE
Then go to the attributes section of the region and map the required columns.
There is an option to do advanced formatting. You can provide the required formatting(width, height etc..) there.
To use the column inside the advanced formatting, use &COLUMN_NAME. as the substution.
Please visit this link for more information
https://blogs.oracle.com/apex/a-simple-guide-to-the-new-cards-region-in-apex-202

How can I keep only 5 features on display with a WMS layer requested from GeoServer via a SQL view?

I set up a PostGIS database that I added in GeoServer via a parameterized SQL view. I use Leaflet to display this layer via WMS.
I would like to limit the number of features I see in the bounding box (5 maximum in my case). I tried to add a LIMIT 5 at the end of my SQL view but it affects the number of features on the whole map not in the bouding box.
Here is a simplified example to illustrate the issue. The aim is to get the 5 most populated cities located in the bounding box. It would work if Geoserver made this query :
SELECT geometry FROM table_cities
WHERE geometry && ST_GeomFromText(
'POLYGON ((-5.185 41.954, -5.185 51.374, 23.378 51.374, 23.378 41.954, -5.185 41.954))',
4326)
ORDER BY population LIMIT 5
But instead it wraps the SQL view inside a new SELECT dedicated to keep only the features located in the bounding box:
SELECT geometry FROM
(SELECT geometry FROM table_cities ORDER BY population LIMIT 5)
WHERE geometry && ST_GeomFromText(
'POLYGON ((-5.185 41.954, -5.185 51.374, 23.378 51.374, 23.378 41.954, -5.185 41.954))',
4326)
Is there a way to force Geoserver to put the bouding box verification before the LIMIT 5 selection?
Or maybe there is a different method to achieve what I want ?
You can add the Geoserver Where Clause placeholder :where_clause:
Because an and is automatically/systematically added, you must already have a where clause, even if it is a dummy 1=1 clause that always evaluate to true.
SELECT geometry
FROM table_cities
WHERE 1 = 1 :where_clause:
ORDER BY population
LIMIT 5
Note the absence of and between the 1=1 and :where_clause:

New to Python and Pandas, Looking for help aggregating observations

I am relatively new to using Python and Pandas, and was looking for help with this line of code:
`Football.ydstogo[Football.ydstogo>='11']&[Football.ydstogo<='19']= '10-plus`'
I am working with data from the NFL, and trying to build a model to predict when a team will pass, or when a team will run the ball. One of my variables (ydstogo) measures the distance for the team, with the ball, to get a first down. I am trying to group together the observations after 10 yards for ease of visualization.
When I tried running the code above, the error in my output is "can't assign to operator". I've used this code before to change gender observations to dummy variables, so I'm confused why it is not working here.
As I understand, you want to find elements with (string)
value between '11' and '19' and set a new string there.
So probably your should change your code to:
Football.ydstogo[(Football.ydstogo >= '11') & (Football.ydstogo <= '19')] = '10-plus'
Alternative:
Football.ydstogo[Football.ydstogo.between('11', '19')] = '10-plus'

Nested Set Analysis in QlikSense

My User_ID has several images and with this piece of code I receive the largest IMAGE_NR .
max({$<USER_ID = {'8638087'}> } IMAGE_NR)
Every image number is linked to an IMAGE_ID. How do I get this?
In words:
Give me IMAGE_ID where IMAGE_NR = largest IMAGE_NR of my USER_ID
I tried following that doesn't work:
sum({$<max({<USER_ID={'8638087'}> } IMAGE_NR)>} IMAGE_ID)
Thank you for any thoughts!
Here is a step-by-step solution.
You mention that this already brings back the correct IMAGE_NR:
max({$<USER_ID = {'8638087'}> } IMAGE_NR)
Now you want the IMAGE_ID. The logic is:
=only({CORRECT_IMAGE_NR_SET_ANALYSIS} IMAGE_ID)
I generally prefer to avoid search mode (double quotes inside element list) and instead use a higher evaluation level on the top calculation, so I would recommend:
$(=
'only({<IMAGE_NR={'
& max({$<USER_ID = {'8638087'}> } IMAGE_NR)
& '}>} IMAGE_ID)'
)
This would also provide you a nice preview formula in the formula editor, something like:
only({<IMAGE_NR={210391287}>} IMAGE_ID)
I didn't test it, but i believe it's something like :
only({<IMAGE_NR={'$(=max(IMAGE_NR))'}, USER_ID={'8638087'}>} IMAGE_ID)
If the dimension of the table is USER_ID then this will return the IMAGE_ID of the maximum IMAGE_NR per USER_ID. Should work / return results for any dimension, but then will have to be read as maximum IMAGE_NR per whatever that dimesion is. The minus on IMAGE_NR is to get the largest/last sorted value
firstsortedvalue(IMAGE_ID,-IMAGE_NR)
If you're using it in a text box with no dimension then you can also add the set analysis
firstsortedvalue({<USER_ID={'8638087'}>} IMAGE_ID,-IMAGE_NR)

How to change SQL WHERE clause through excel?

I have build a SQL query to provide me historical price data of a product, which I intent to use in excel (pivot, graphs, all of that fancy excel stuff).
The problem now is that, due to the nature of many products and many price changes, I can not get all the products loaded that I intent to.
I somehow need to tell excel that has to change a couple numbers in the connected SQL query, i.e. through a text box and then load the query again. Otherwise I will always open up the query editor in excel and change it manually, which takes quite a bit.
I reckon I will have to use some sort of macro or VBA, but I have never used it. If anyone could refer an article that would be great, as i could not find anything helpful.
Some code:
WHERE
PD.Product_Id = '11761476' < I will have to change that number
AND
PSPH.[Valid_To] > '2018-01-01'
ORDER BY
PSPH.[Valid_To]
To manipulate the SQL string, you could do something like this..
pid = "11761476"
validto = "2018-01-01"
SQLtemplate = "WHERE PD.Product_Id = '[prodID]' AND PSPH.[Valid_To] > '[validto]' ORDER BY PSPH.[Valid_To]"
Sql = Replace(SQLtemplate, "[prodID]", pid)
Sql = Replace(Sql, "[validto]", validto)
but before you can use that, you'll need to follow #Foxfire's advice and record a macro while you're changing it manually to see exactly what needs to change, and how.
You can put this instead in the connection:
WHERE
PD.Product_Id = '11761476' < ?
AND
PSPH.[Valid_To] > '2018-01-01'
ORDER BY
PSPH.[Valid_To]
And then save the connection.
The first time it will run, a prompt will ask you where to find the parameter, and you can choose the cell.
Let me know if it works!
Cheers,
Arnaud