I have two datasets with Client, 1st Nationality, 2nd Nationality, 3rd Nationality and with Country Code, Continent.
I would need an expresion using an expresion board in Palantir Contour that would select for me a client from the furthest contienet (in case the client has more than one nationality, it selects the farthest one assuming I am in America) when I make ulitimately a pilot table having only Continents and count of clients in it. If not directly palantir expression, also an SQL statement for this would be helpful. THank you
Sample example
I have two datasets with Client, 1st Nationality, 2nd Nationality, 3rd Nationality and with Country Code, Continent.
I would need an expresion using an expresion board in Palantir Contour that would select for me a client from the furthest contienet (in case the client has more than one nationality, it selects the farthest one assuming I am in America) when I make ulitimately a pilot table having only Continents and count of clients in it. If not directly palantir expression, also an SQL statement for this would be helpful. THank you
Sample example
Share Improve this question edited Feb 5 at 16:23 Turpan asked Feb 5 at 15:05 TurpanTurpan 5352 gold badges8 silver badges19 bronze badges 3- Please provide a minimal reproducible example with sample data and desired results. – Dale K Commented Feb 5 at 15:28
- Ciao Dale K, thanks for your comment, I have added as requested. – Turpan Commented Feb 5 at 16:24
- Please don't use images for data - use table markdown – Dale K Commented Feb 5 at 16:35
1 Answer
Reset to default 0So we have to work on the following tables-
To find the furthest continent for each client, our condition is America is the closest continent and Asia is the furthest continent after Europe. Try the following SQL code-
WITH Client_Continents AS (
SELECT
cn.Client,
c.Continent,
CASE
WHEN c.Continent = 'America' THEN 1
WHEN c.Continent = 'Europe' THEN 2
WHEN c.Continent = 'Asia' THEN 3
ELSE 0
END AS ContinentScore
FROM Client_Nationality cn
LEFT JOIN Continent c ON cn.First_Nationality = c.Country_Code
UNION ALL
SELECT
cn.Client,
c.Continent,
CASE
WHEN c.Continent = 'America' THEN 1
WHEN c.Continent = 'Europe' THEN 2
WHEN c.Continent = 'Asia' THEN 3
ELSE 0
END AS ContinentScore
FROM Client_Nationality cn
LEFT JOIN Continent c ON cn.Second_Nationality = c.Country_Code
UNION ALL
SELECT
cn.Client,
c.Continent,
CASE
WHEN c.Continent = 'America' THEN 1
WHEN c.Continent = 'Europe' THEN 2
WHEN c.Continent = 'Asia' THEN 3
ELSE 0
END AS ContinentScore
FROM Client_Nationality cn
LEFT JOIN Continent c ON cn.third_Nationality = c.Country_Code
),
Max_Continent AS (
SELECT
Client,
MAX(ContinentScore) AS MaxContinentScore
FROM Client_Continents
GROUP BY Client
)
SELECT
cc.Continent,
COUNT(DISTINCT cc.Client) AS ClientCount
FROM Client_Continents cc
JOIN Max_Continent mc ON cc.Client = mc.Client
WHERE cc.ContinentScore = mc.MaxContinentScore
GROUP BY cc.Continent
ORDER BY ClientCount;
Provides the result set -