function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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.
AVIJIT DAS 32AVIJIT DAS 32
@
Emilien Guichard 40

Hi,
have tried with the query  :

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';


but it's not returning and also not showing an error , it look like it's loading but i waited for 30-40 mins it's not returning with results . Still showing it's loading. 

Please help me on this.
Lucas Fernando Costa 9Lucas Fernando Costa 9
HI AVIJIT DAS 32, try to edit your query step directly in the JSON mode. Hope it help you
  • First creates a similar query in SAQL in Churn Tenure step:

q = load \"Beattie_Subs\";
q = filter q by 'Tenure' => 50;
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';
  • ​​​​​Edit in the JSON mode (ctrl+e) and add the bind {{row(Tenure_Lenght_1.selection,[0],[\"min\",\"max\"]).asRange(\"Tenure\")}}
q = load \"Beattie_Subs\";
q = filter q by {{row(Tenure_Lenght_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'
  • Move the Tenure Length step above this step
"Tenure_Lenght_1": {
"broadcastFacet": true,
"columns": {
"min": {
"type": "string"
},
"max": {
"type": "string"
},
"value": {
"type": "string"
},
"Display": {
"type": "string"
}
},
"label": "Tenure Lenght",
"selectMode": "single",
"type": "staticflex",
"values": [
{
"Display": "High Risk",
"min": 1,
"max": 12,
"value": "1 to 12 months"
},
{
"Display": "Medium Risk",
"min": 13,
"max": 24,
"value": "13 to 24 months"
},
{
"Display": "Low Risk",
"min": 25,
"max": 36,
"value": "25 to 36 months"
}
]
},
"Churn_Tenure_1": {
"broadcastFacet": true,
"groups": [],
"label": "Churn Tenure",
"numbers": [],
"query": "q = load \"Beattie_Subs\";\nq = filter q by {{row(Tenure_Lenght_1.selection,[0],[\"min\",\"max\"]).asRange(\"Tenure\")}};\nq_B = filter q by 'Churn' == \"Yes\";\nresult = group q by all full, q_B by all;\nresult = group q by all full, q_B by all;\nresult = foreach result generate (count(q_B) / count(q))*100 as 'churnRate';",
"receiveFacetSource": {
"mode": "all",
"steps": []
},
"selectMode": "single",
"strings": [],
"type": "saql",
"useGlobal": true,
"visualizationParameters": {
"parameters": {
"autoFitMode": "keepLabels",
"max": 100,
"legend": {
"showHeader": true,
"show": false,
"position": "right-top",
"inside": false
},
"icon": "circle",
"iconRounding": "none",
"visualizationType": "rating",
"title": {
"fontSize": 14,
"subtitleFontSize": 11,
"label": "",
"align": "center",
"subtitleLabel": ""
},
"trellis": {
"flipLabels": false,
"showGridLines": true,
"size": [
100,
100
],
"enable": false,
"type": "x",
"chartsPerLine": 4
},
"colors": {
"lowColor1": "#1674D9",
"highColor1": "#1674D9"
},
"high": 50,
"showActionMenu": true,
"min": 0,
"numberOfIcons": 10,
"valueType": "compactNumber",
"valuesOnLeft": false,
"theme": "wave",
"applyConditionalFormatting": true,
"showMax": false
},
"type": "chart"
}
},
"Churn_Rate_1": {
Teresa AlukuTeresa Aluku
Hello, I am unable to get the toggle work...any advice?
Pavan Nandan 31Pavan Nandan 31
Hi All,

I have Stucked in challange 2

I have created the tresure length like this
Tresure Length

and my Query/json is like below:
"Tenure_Lenght_1": {
"broadcastFacet": true,
"columns": {
"min": {
"type": "string"
},
"max": {
"type": "string"
},
"value": {
"type": "string"
},
"Display": {
"type": "string"
}
},
"label": "Tenure Lenght",
"selectMode": "single",
"type": "staticflex",
"values": [
{
"Display": "High Risk",
"min": 1,
"max": 12,
"value": "1 to 12 months"
},
{
"Display": "Medium Risk",
"min": 13,
"max": 24,
"value": "13 to 24 months"
},
{
"Display": "Low Risk",
"min": 25,
"max": 36,
"value": "25 to 36 months"
}
]
},

have tried with the query  :

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';


but it's not returning and also not showing an error , it look like it's loading but i waited for 30-40 mins it's not returning with results . Still showing it's loading. 

Please help me here! Thanks in advance!
shruthi haridas 4shruthi haridas 4
Same isse as Pavan. Please let me know if you are able to go ahead
Pramita C 1Pramita C 1
1) Click on Create Query in the dashboard and then select custom query,User-added image
2) Add a toggle in the dashboard and in properties:
User-added image
drag the tenure length over the toggle
3) Add a chart and in the advanced editor, 
Select query as Toggle query and then choose min max 
User-added image
and then choose selection :
User-added image 
edit fieldname as Tenure and copy paste in the query :
"query": "q = load \"Beattie_Subs\";\nq = filter q by {{row(Tenure_Length_1.selection, [0], [\"min\", \"max\"]).asRange(\"Tenure\")}};\nq_B = filter q by 'Churn' == \"Yes\";\nresult = group q by all full, q_B by all;\nresult = foreach result generate (count(q_B) / count(q))*100 as 'churnRate';",
superbadge analysticssuperbadge analystics

can i Please get help with challenge 2 I have been trying to follow but unable to get past it 

Can somone please lay down the steps that need to be followed