<?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 Re: Arcade Data Expression: seperate data by month in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-seperate-data-by-month/m-p/1077720#M4776</link>
    <description>&lt;P&gt;Got it solved by the following expression (see result below). If there are any suggestions how to write a more elegant code, I would still appreaciate to learn it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;var p = "https://herewegrow.maps.arcgis.com"
var itemID = "f8602c47a194470b89a75174a9d1153b"
var layerID = 0

var attendance = FeatureSetByPortalItem( Portal(p),itemID,layerID, ["CreationDate", "FT_Name", ""], false );
var currentMonISO = ISOMonth(today());
var oneMonAgoISO = currentMonISO-1;
var twoMonAgoISO = currentMonISO-2;
var currentMon = Decode(currentMonISO,    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data");
var oneMonAgo = Decode(oneMonAgoISO,    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data");
var twoMonAgo = Decode(twoMonAgoISO,    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data");

var dict = {
  fields: [
    { name: "FT_Name", type: "esriFieldTypeString" },
    { name: "month", type: "esriFieldTypeString" },
    { name: "Year", type: "esriFieldTypeString" },
  ],
  geometryType: "",
  features: [],
};
var index = 0; 
for (var feature in attendance) { 
    dict.features[index] = { 
        "attributes": { 
            "FT_Name": Text(feature["FT_Name"]), 
            "month": Decode(ISOMonth(feature["CreationDate"]),    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data"),
            "Year": ISOYear(feature["CreationDate"]),
        }} 
    index++;} 
var fs_dict = FeatureSet(Text(dict));

var currentMon = filter(fs_dict, "month = @currentMon");
var oneMonAtt = filter(fs_dict, "month = @oneMonAgo");
var twoMonAtt = filter(fs_dict, "month = @twoMonAgo");

var cDict = {
  fields: [
    { name: "FT_Name", type: "esriFieldTypeString" },
    { name: "currentMon", type: "esriFieldTypeString" },
    { name: "oneMonAgo", type: "esriFieldTypeString" },
    { name: "twoMonAgo", type: "esriFieldTypeString" },
    { name: "Year", type: "esriFieldTypeString" },
  ],
  geometryType: "",
  features: [],
};

var i = 0;
for (var c in currentMon) {
    cDict.features[i++] = {
        attributes: {
            FT_Name: c["FT_Name"],
            oneMonAgo: c["month"],
            Year: c["year"],
        },
    };
}

for (var o in oneMonAtt) {
    cDict.features[i++] = {
        attributes: {
            FT_Name: o["FT_Name"],
            oneMonAgo: o["month"],
            Year: o["year"],
        },
    };
}

for (var t in twoMonAtt) {
    cDict.features[i++] = {
        attributes: {
            FT_Name: t["FT_Name"],
            twoMonAgo: t["month"],
            Year: t["year"],
        },
    };
}
var fs_cDict = FeatureSet(Text(cDict));

var result = GroupBy(fs_cDict, ["FT_Name", "Year"],
[{
    name: "current Month",
    expression: "currentMon",
    statistic: "COUNT"
},{
    name: "one month ago",
    expression: "oneMonAgo",
    statistic: "COUNT"
},
{
    name: "two months ago",
    expression: "twoMonAgo",
    statistic: "COUNT"
}]);

return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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="jztu6tr.PNG" style="width: 733px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/18209iC12B499513A12440/image-size/large?v=v2&amp;amp;px=999" role="button" title="jztu6tr.PNG" alt="jztu6tr.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 09:06:33 GMT</pubDate>
    <dc:creator>Merlin</dc:creator>
    <dc:date>2021-07-12T09:06:33Z</dc:date>
    <item>
      <title>Arcade Data Expression: seperate data by month</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-seperate-data-by-month/m-p/1075833#M4752</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;as a newcomer to Arcade data expressions in the dashboards (and in general) I have had an exiting day so far playing around with my data.&lt;/P&gt;&lt;P&gt;My current challenge has brought me now to a point of trickyness I havn't been able to overcome. Maybe someone out there might help me out?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;*** the data ***&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;is a featureset called by &lt;EM&gt;FeatureSetByPortalItem()&lt;/EM&gt; with two fields ['&lt;EM&gt;CreationDate&lt;/EM&gt;', '&lt;EM&gt;Name&lt;/EM&gt;'],&lt;/P&gt;&lt;P&gt;the return on this looks like:&lt;/P&gt;&lt;TABLE border="1" width="99.95748299319727%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.29081632653062%" height="30px"&gt;&lt;STRONG&gt;objectid&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;STRONG&gt;CreationDate&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.29081632653062%" height="24px"&gt;41&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Me&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;03 May 2021 10:17:42 am&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.29081632653062%" height="24px"&gt;42&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Me&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;03 Jun 2021 10:21:56 am&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;43&lt;/TD&gt;&lt;TD height="24px"&gt;Fa&lt;/TD&gt;&lt;TD height="24px"&gt;03 May 2021 10:28:56 am&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;44&lt;/TD&gt;&lt;TD height="24px"&gt;Fa&lt;/TD&gt;&lt;TD height="24px"&gt;03 Jun 2021 09:17:56 am&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;45&lt;/TD&gt;&lt;TD height="24px"&gt;Fa&lt;/TD&gt;&lt;TD height="24px"&gt;03 May 2021 10:54:56 am&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;46&lt;/TD&gt;&lt;TD&gt;Ki&lt;/TD&gt;&lt;TD&gt;03 Jun 2021 08:17:56 am&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;...&lt;/TD&gt;&lt;TD height="24px"&gt;...&lt;/TD&gt;&lt;TD height="24px"&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the table continues with several hundred entries of around 10 different names and unique creation dates ranging from beginning of May until end on June.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;*** the desired result ***&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;is a featureset which is returned by the expression in the following fashion:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;two months ago&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;one month ago&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;current month&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Me&lt;/TD&gt;&lt;TD width="25%"&gt;12&lt;/TD&gt;&lt;TD width="25%"&gt;14&lt;/TD&gt;&lt;TD width="25%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Fa&lt;/TD&gt;&lt;TD width="25%"&gt;10&lt;/TD&gt;&lt;TD width="25%"&gt;10&lt;/TD&gt;&lt;TD width="25%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Ki&lt;/TD&gt;&lt;TD width="25%"&gt;14&lt;/TD&gt;&lt;TD width="25%"&gt;12&lt;/TD&gt;&lt;TD width="25%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is important to avoid static months (e.g. May instead of "two months ago"), as the featureset shall always display the latest data.&lt;/P&gt;&lt;P&gt;The values in the colums &lt;EM&gt;two months ago&lt;/EM&gt;, &lt;EM&gt;one month ago&lt;/EM&gt; &amp;amp; &lt;EM&gt;current &lt;/EM&gt;are the result of a count calculation. It shall indicate how many entries have been made per Name in the respective months. As there are no submissions in the current month, it shall display a 0.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;*** the code so far ***&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Now to the most important part. Here my commented code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;var p = 'https://xxx.maps.arcgis.com'
var itemID = 'xxx'
var layerID = 0

var attendance = FeatureSetByPortalItem( Portal(p),itemID,layerID, ['CreationDate', 'FT_Name'], false );

// three variables to determine the current, last and second last month

var currentMonISO = ISOMonth(today());
var oneMonAgoISO = currentMonISO-1;
var twoMonAgoISO = currentMonISO-2;

//empty dictonary to store the desired result

var dict = {
fields: [
{ name: "FT_Name", type: "esriFieldTypeString" },
{ name: "month", type: "esriFieldTypeString" },
{ name: "Year", type: "esriFieldTypeString" },
// { name: "list_custom_order", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: [],
};

// looping through the featureset to populate the dictionary with data and converting the Months into human language

var index = 0;

for (var feature in attendance) {
dict.features[index] = {
'attributes': {
'FT_Name': Text(feature["FT_Name"]),
'month': Decode(ISOMonth(feature["CreationDate"]),
1, "Jan",
2, "Feb",
3, "Mar",
4, "Apr",
5, "May",
6, "Jun",
7, "Jul",
8, "Aug",
9, "Sep",
10, "Oct",
11, "Nov",
12, "Dec",
"missing data"),
'Year': ISOYear(feature["CreationDate"]),
}}
index++;}

var fs_dict = FeatureSet(Text(dict));

// using GroupBy() to display the data grouped by name
var groupName = GroupBy(fs_dict, ["FT_Name","month", "year"], [
{
name: "trainings per month",
expression: "month",
statistic: "COUNT"
}])

return groupName&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;*** further approach ***&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;the code so far gives me a featureset in the following fashion:&lt;/P&gt;&lt;TABLE border="1" width="56.249205642555594%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="46px"&gt;name&lt;/TD&gt;&lt;TD width="25%" height="46px"&gt;month&lt;/TD&gt;&lt;TD width="25%" height="46px"&gt;number of submissions&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="24px"&gt;Me&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;May&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;Me&lt;/TD&gt;&lt;TD height="24px"&gt;Jun&lt;/TD&gt;&lt;TD height="24px"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;Fa&lt;/TD&gt;&lt;TD height="24px"&gt;May&lt;/TD&gt;&lt;TD height="24px"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;...&lt;/TD&gt;&lt;TD height="24px"&gt;...&lt;/TD&gt;&lt;TD height="24px"&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I could create a second dictionary with the fields I would like to see:&lt;/P&gt;&lt;P&gt;var dictTwo = {&lt;BR /&gt;fields: [&lt;BR /&gt;{ name: "FT_Name", type: "esriFieldTypeString" },&lt;BR /&gt;{ name: "oneMon", type: "esriFieldTypeString" },&lt;BR /&gt;{ name: "twoMon", type: "esriFieldTypeString" },&lt;BR /&gt;{ name: "Year", type: "esriFieldTypeString" },&lt;BR /&gt;],&lt;BR /&gt;geometryType: "",&lt;BR /&gt;features: [],&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;My idea so far was to somehow filter the featureset populating the dictionary. But I didnt manage to modify the first method to populate the dictionary via for() loop in a way that I would get what I was looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for reading my lengthy post, and thanks in advance for making any suggestions.&lt;/P&gt;&lt;P&gt;All the best,&lt;BR /&gt;Merlin&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 13:50:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-seperate-data-by-month/m-p/1075833#M4752</guid>
      <dc:creator>Merlin</dc:creator>
      <dc:date>2021-07-06T13:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression: seperate data by month</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-seperate-data-by-month/m-p/1077720#M4776</link>
      <description>&lt;P&gt;Got it solved by the following expression (see result below). If there are any suggestions how to write a more elegant code, I would still appreaciate to learn it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;var p = "https://herewegrow.maps.arcgis.com"
var itemID = "f8602c47a194470b89a75174a9d1153b"
var layerID = 0

var attendance = FeatureSetByPortalItem( Portal(p),itemID,layerID, ["CreationDate", "FT_Name", ""], false );
var currentMonISO = ISOMonth(today());
var oneMonAgoISO = currentMonISO-1;
var twoMonAgoISO = currentMonISO-2;
var currentMon = Decode(currentMonISO,    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data");
var oneMonAgo = Decode(oneMonAgoISO,    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data");
var twoMonAgo = Decode(twoMonAgoISO,    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data");

var dict = {
  fields: [
    { name: "FT_Name", type: "esriFieldTypeString" },
    { name: "month", type: "esriFieldTypeString" },
    { name: "Year", type: "esriFieldTypeString" },
  ],
  geometryType: "",
  features: [],
};
var index = 0; 
for (var feature in attendance) { 
    dict.features[index] = { 
        "attributes": { 
            "FT_Name": Text(feature["FT_Name"]), 
            "month": Decode(ISOMonth(feature["CreationDate"]),    
            1, "Jan",
            2, "Feb",
            3, "Mar",
            4, "Apr",
            5, "May",
            6, "Jun",
            7, "Jul",
            8, "Aug",
            9, "Sep",
            10, "Oct",
            11, "Nov",
            12, "Dec",
            "missing data"),
            "Year": ISOYear(feature["CreationDate"]),
        }} 
    index++;} 
var fs_dict = FeatureSet(Text(dict));

var currentMon = filter(fs_dict, "month = @currentMon");
var oneMonAtt = filter(fs_dict, "month = @oneMonAgo");
var twoMonAtt = filter(fs_dict, "month = @twoMonAgo");

var cDict = {
  fields: [
    { name: "FT_Name", type: "esriFieldTypeString" },
    { name: "currentMon", type: "esriFieldTypeString" },
    { name: "oneMonAgo", type: "esriFieldTypeString" },
    { name: "twoMonAgo", type: "esriFieldTypeString" },
    { name: "Year", type: "esriFieldTypeString" },
  ],
  geometryType: "",
  features: [],
};

var i = 0;
for (var c in currentMon) {
    cDict.features[i++] = {
        attributes: {
            FT_Name: c["FT_Name"],
            oneMonAgo: c["month"],
            Year: c["year"],
        },
    };
}

for (var o in oneMonAtt) {
    cDict.features[i++] = {
        attributes: {
            FT_Name: o["FT_Name"],
            oneMonAgo: o["month"],
            Year: o["year"],
        },
    };
}

for (var t in twoMonAtt) {
    cDict.features[i++] = {
        attributes: {
            FT_Name: t["FT_Name"],
            twoMonAgo: t["month"],
            Year: t["year"],
        },
    };
}
var fs_cDict = FeatureSet(Text(cDict));

var result = GroupBy(fs_cDict, ["FT_Name", "Year"],
[{
    name: "current Month",
    expression: "currentMon",
    statistic: "COUNT"
},{
    name: "one month ago",
    expression: "oneMonAgo",
    statistic: "COUNT"
},
{
    name: "two months ago",
    expression: "twoMonAgo",
    statistic: "COUNT"
}]);

return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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="jztu6tr.PNG" style="width: 733px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/18209iC12B499513A12440/image-size/large?v=v2&amp;amp;px=999" role="button" title="jztu6tr.PNG" alt="jztu6tr.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 09:06:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-seperate-data-by-month/m-p/1077720#M4776</guid>
      <dc:creator>Merlin</dc:creator>
      <dc:date>2021-07-12T09:06:33Z</dc:date>
    </item>
  </channel>
</rss>

