0

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

enter image description here

3
  • Please provide a minimal reproducible example with sample data and desired results. Commented Feb 5 at 15:28
  • Ciao Dale K, thanks for your comment, I have added as requested. Commented Feb 5 at 16:24
  • Please don't use images for data - use table markdown Commented Feb 5 at 16:35

1 Answer 1

0

So we have to work on the following tables-input 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 -

result set

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, it seems like working :) But I got also a NULL category in the continent column, what data does it refer to?
This will happen when none of the client nationality values match a valid country code in the continent table.
perfect, would you be able to such a way that could display also type of client please? I have two types, let's say A and B that is in a next column), so finaly the there would be under each continent Type A and its ClientCount and Type B and its ClientCount.
You may keep the client type information in separate table. Then do join operation in the last select query and also group by client type.
I have actually client type information in the Client_Nationality table. Can I do it without join?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.