+ Start a Discussion
Brian KesslerBrian Kessler 

Einstein Analytics and Discovery Insights Specialist Challenge 2: What is wrong with my SAQL query?

I'm currently still struggling with Einstein Analytics and Discovery Insights Specialist (https://trailhead.salesforce.com/en/content/learn/superbadges/superbadge_analytics_insights_specialist?trailmix_creator_id=briankessler&trailmix_id=getting-started-with-analytics) Challenge 2:

My SAQL query is now:
 
beattieSubscribers = load "Beattie_Subs";
tenuredSubscribers = filter beattieSubscribers by row(
               Tenure_Length.selection, 
               [0], 
               ["min","max"]
          ).asRange("Tenure");
churnSubscribers = filter tenuredSubscribers by 'Churn' == "Yes";
groupedSubscribers = group tenuredSubscribers by all full, churnSubscribers by all;
churnRate = foreach groupedSubscribers generate (count(churnSubscribers) / count(tenuredSubscribers))*100 as 'churnRate';

However, this results in the following error displayed on the page:
 
Function doesn't have a type check definition:

.
What is wrong here and how can/should I fix this?

Thanks?
Best Answer chosen by Brian Kessler
Emilien Guichard 40Emilien Guichard 40
Hi Brian,

Here is the code I used :

Churn Tenure step :
q = load "Beattie_Subs";
filter q by {{row(Tenure_Length_1.selection,[0],[\"min\",\"max\"]).asRange (\"Tenure\")}};q_B = filter q by 'Churn' == "Yes";
result = group q by all full, q_B by all;
result = foreach result generate (count(q_B) / count(q))*100 as 'churnRate';

Toggle widget :
"Tenure_Length_1": {
                "broadcastFacet": true,
                "label": "Tenure Length",
                "selectMode": "single",
                "type": "staticflex",
                "values": [
                    {
                        "display": "High Risk",
                        "value": "1 to 12 months",
                        "min": 1,
                        "max": 12
                    },
                    {
                        "display": "Medium Risk",
                        "value": "13 to 24 months",
                        "min": 13,
                        "max": 24
                    },
                    {
                        "display": "Low Risk",
                        "value": "25 to 36 months",
                        "min": 25,
                        "max": 36
                    }
                ]
            },


 

All Answers

Emilien Guichard 40Emilien Guichard 40
Hi Brian,

Here is the code I used :

Churn Tenure step :
q = load "Beattie_Subs";
filter q by {{row(Tenure_Length_1.selection,[0],[\"min\",\"max\"]).asRange (\"Tenure\")}};q_B = filter q by 'Churn' == "Yes";
result = group q by all full, q_B by all;
result = foreach result generate (count(q_B) / count(q))*100 as 'churnRate';

Toggle widget :
"Tenure_Length_1": {
                "broadcastFacet": true,
                "label": "Tenure Length",
                "selectMode": "single",
                "type": "staticflex",
                "values": [
                    {
                        "display": "High Risk",
                        "value": "1 to 12 months",
                        "min": 1,
                        "max": 12
                    },
                    {
                        "display": "Medium Risk",
                        "value": "13 to 24 months",
                        "min": 13,
                        "max": 24
                    },
                    {
                        "display": "Low Risk",
                        "value": "25 to 36 months",
                        "min": 25,
                        "max": 36
                    }
                ]
            },


 
This was selected as the best answer
Brian KesslerBrian Kessler
Ack!
There is no confirmation button on this page.
There is no undo button on this page.
I just clicked on the wrong place on the page and suddenly the above answer was accepted as "best answer", but it did NOT actually work.

If I entered the formula as-is into the SAQL editor, the editor just becomes unresposive.

I added some more \ marks before the quotes and put it into the json along with a property name "query", but nothing displays and if I try to save, I get: 
 
Error saving dashboard

Unrecognized field "query" at [line:1, column:1481]

The relevant part of my JSON now looks like this:

 
"Tenure_Length_1": {
                "broadcastFacet": true,
                "label": "Tenure Length",
                "query": "q = load \"Beattie_Subs\";\r\nfilter q by {{row(Tenure_Length_1.selection,[0],[\"min\",\"max\"]).asRange (\"Tenure\")}};\r\nq_B = filter q by 'Churn' == \"Yes\";\r\nresult = group q by all full, q_B by all;\r\nresult = foreach result generate (count(q_B) / count(q))*100 as 'churnRate';\r\n",
                "selectMode": "single",
                "type": "staticflex",
                "values": [
                    "{\"display\":\"High Risk\",\"value\":\"1 to 12 months\",\"min\":1,\"max\":12}",
                    "{\"display\":\"Medium Risk\",\"value\":\"13 to 24 months\",\"min\":13,\"max\":24}",
                    "{\"display\":\"Low Risk\",\"value\":\"25 to 36 months\",\"min\":25,\"max\":36}"
                ]
            },






 
Brian KesslerBrian Kessler
@Emilien Guichard 40's answer is in fact correct.  :-)
I was just being dense and mixing up the steps.