<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Convert Text to Number Using Arcade and Get Average in ArcGIS Dashboards in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/convert-text-to-number-using-arcade-and-get/m-p/1262380#M7411</link>
    <description>&lt;P&gt;Hi! I have a training evaluation survey form that gets feedback and returns 5,4,3,2,1. For every item that they need to rate, Survey123 returns strings (5,4,3,2,1 in text format). I need to convert this to numeric so that I can get the average for every item and then get the average for each category. Thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2023 10:28:37 GMT</pubDate>
    <dc:creator>GeodataSystems</dc:creator>
    <dc:date>2023-02-28T10:28:37Z</dc:date>
    <item>
      <title>Convert Text to Number Using Arcade and Get Average in ArcGIS Dashboards</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/convert-text-to-number-using-arcade-and-get/m-p/1262380#M7411</link>
      <description>&lt;P&gt;Hi! I have a training evaluation survey form that gets feedback and returns 5,4,3,2,1. For every item that they need to rate, Survey123 returns strings (5,4,3,2,1 in text format). I need to convert this to numeric so that I can get the average for every item and then get the average for each category. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 10:28:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/convert-text-to-number-using-arcade-and-get/m-p/1262380#M7411</guid>
      <dc:creator>GeodataSystems</dc:creator>
      <dc:date>2023-02-28T10:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text to Number Using Arcade and Get Average in ArcGIS Dashboards</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/convert-text-to-number-using-arcade-and-get/m-p/1262421#M7412</link>
      <description>&lt;P&gt;To get the average of a featureset column , we can use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#average" target="_blank" rel="noopener"&gt;Average()&lt;/A&gt; function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's load some test data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// create a test fs for a scoring survey.
// 3 text fields with scores between 1 and 5
var survey_dict = {
    fields:[
        {name: "Score1", type: "esriFieldTypeString"},
        {name: "Score2", type: "esriFieldTypeString"},
        {name: "Score3", type: "esriFieldTypeString"},
        ],
    geometryType: "",
    features: []
}
for(var i = 0; i &amp;lt; 200; i++) {
    var rating = {attributes: {
        Score1: Text(Round(4 * Random() + 1)),
        Score2: Text(Round(4 * Random() + 1)),
        Score3: Text(Round(4 * Random() + 1)),
    }}
    Push(survey_dict.features, rating)
}
var survey = Featureset(Text(survey_dict))
// return survey&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1677588916430.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63870i674F4A6C05A72598/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1677588916430.png" alt="JohannesLindner_0-1677588916430.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, if we take the Average() of column Score1, we get this result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1677589000954.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63872i0B4CAB8D01503946/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1677589000954.png" alt="JohannesLindner_0-1677589000954.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is obviously incorrect. It seems like the function doesn't convert to Number(), but instead somehow uses the bytes of the string values as number (or something else...).&lt;/P&gt;&lt;P&gt;So we need to covert that column to a proper integer column first. I haven't found a way to do that inside the Average() function, so we should probably just convert the featureset before calling Average():&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var score_fields = ["Score1", "Score2", "Score3"]
// create an empty featureset dict
var numeric_survey_dict = {
    fields: [],
    geometryType: "",
    features: []
}
// add the score fields as integer fields
for(var i in score_fields) {
    var field = {name: score_fields[i], type: "esriFieldTypeInteger"}
    Push(numeric_survey_dict.fields, field)
}
// go thorugh the original featureset and convert each value to Number()
for(var f in survey) {
    var converted_f = Dictionary()
    for(var i in score_fields) {
        var field = score_fields[i]
        converted_f[field] = Number(f[field])
    }
    Push(numeric_survey_dict.features, {attributes: converted_f})
}
// convert the dictionary to a featureset
var numeric_survey = Featureset(Text(numeric_survey_dict))

// get the Average()
return Average(numeric_survey, "Score1")&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1677589720748.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63875iF6C91C879519FCDF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1677589720748.png" alt="JohannesLindner_1-1677589720748.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 13:09:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/convert-text-to-number-using-arcade-and-get/m-p/1262421#M7412</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-02-28T13:09:42Z</dc:date>
    </item>
  </channel>
</rss>

