<?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: Create a table with domains as columns in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595332#M10886</link>
    <description>&lt;P&gt;Can you give a better idea of what you'd like your final table to look like? Are you trying to get a summary of how many records are in the domains for each pair of fields? I'm guessing if your table looks like this&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;id&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;Field 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;Field2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;1&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 2&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;3&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 3&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;4&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;5&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you want your output table looking like this.&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;Field 2, domain 1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;Field 2, domain 2&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;Field 2, domain 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;Field 1, domain 1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;2&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;Field 1, domain 2&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;Field 1, domain 3&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;</description>
    <pubDate>Thu, 13 Mar 2025 19:04:39 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2025-03-13T19:04:39Z</dc:date>
    <item>
      <title>Create a table with domains as columns</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595032#M10872</link>
      <description>&lt;P&gt;I am trying to use the table widget to build a table that has grouped values for both columns and rows. Eg this example:&lt;/P&gt;&lt;TABLE width="341"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="149"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="64"&gt;Field 2, domain 1&lt;/TD&gt;&lt;TD width="64"&gt;Field 2, domain 2&lt;/TD&gt;&lt;TD width="64"&gt;Field 2, domain 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Field 1, domain 1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Field 1, domain 2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Field 1, domain 3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously rows are easy but if i understand correctly i would need to restructure my data so that i have a column for each of the domains in Field 2? I have tried to do this with arcade and get to the point where I have a dictionary but cannot convert it into a featureset to use in the table.. Here is where I am at with the code, but I am getting an error with the push function.&lt;/P&gt;&lt;P&gt;I am new to arcade so am probably making many mistakes, Any help is appreciated!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;// Define the field to extract coded domains from&lt;BR /&gt;var targetField = "sys_workflow_status"; // Change this to match the actual field name&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var fs = FeatureSetByPortalItem(&lt;BR /&gt;Portal("portall"), // URL to your Portal or ArcGIS Online&lt;BR /&gt;"id", // Replace with your actual layer item ID&lt;BR /&gt;0, // Layer index (0 for the first layer)&lt;BR /&gt;["*"] // Fields to include (all fields in this case)&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;// Check if the feature set is empty&lt;BR /&gt;if (IsEmpty(fs)) {&lt;BR /&gt;return "Error: No features found in this dataset.";&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Get the schema for the layer to retrieve domain information&lt;BR /&gt;var layerSchema = Schema(fs);&lt;BR /&gt;var fieldNames = [];&lt;/P&gt;&lt;P&gt;// Loop through the schema fields to extract field names&lt;BR /&gt;for (var i = 0; i &amp;lt; Count(layerSchema.fields); i++) {&lt;BR /&gt;var field = layerSchema.fields[i];&lt;BR /&gt;Push(fieldNames, field.name); // Access the 'name' property of the field object&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Check if the target field exists in the list of field names&lt;BR /&gt;var fieldIndex = IndexOf(fieldNames, targetField);&lt;/P&gt;&lt;P&gt;// If the field does not exist, return an error&lt;BR /&gt;if (fieldIndex == -1) {&lt;BR /&gt;return "Error: Field '" + targetField + "' not found in the feature set.";&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Retrieve the domain information for the target field&lt;BR /&gt;var domainInfo = null;&lt;BR /&gt;for (var i = 0; i &amp;lt; Count(layerSchema.fields); i++) {&lt;BR /&gt;var field = layerSchema.fields[i];&lt;BR /&gt;// Check if the field has a domain (not null or undefined)&lt;BR /&gt;if (field.name == targetField &amp;amp;&amp;amp; field.domain != null) {&lt;BR /&gt;domainInfo = field.domain;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// If no domain is found, return a message&lt;BR /&gt;if (domainInfo == null) {&lt;BR /&gt;return "Error: No domain found for field '" + targetField + "'.";&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Create a dictionary of domain mappings (assumes it's a coded value domain)&lt;BR /&gt;var domainMappings = {};&lt;BR /&gt;if (domainInfo.type == "codedValue") {&lt;BR /&gt;// If the domain type is coded value, we can extract the coded values and their descriptions&lt;BR /&gt;for (var i = 0; i &amp;lt; Count(domainInfo.codedValues); i++) {&lt;BR /&gt;var codedValue = domainInfo.codedValues[i];&lt;BR /&gt;domainMappings[codedValue.code] = codedValue.name;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Create a dictionary to store the modified feature results&lt;BR /&gt;var resultDict = {};&lt;/P&gt;&lt;P&gt;// Loop through all the features in the feature set&lt;BR /&gt;for (var f in fs) {&lt;/P&gt;&lt;P&gt;// Create a new result object for each feature, starting with the original attributes&lt;BR /&gt;var featureResult = {};&lt;BR /&gt;var geom = Geometry(f); // Get the geometry from the original feature&lt;/P&gt;&lt;P&gt;// Copy the original fields into the result (to retain the original attributes)&lt;BR /&gt;for (var fieldName in f) {&lt;BR /&gt;featureResult[fieldName] = f[fieldName];&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Get the value for the target field in the current feature&lt;BR /&gt;var targetValue = f[targetField];&lt;/P&gt;&lt;P&gt;// Loop through the domain mappings and create a new column for each domain value&lt;BR /&gt;for (var domainCod in domainMappings) {&lt;BR /&gt;var domainValue = domainMappings[domainCod];&lt;/P&gt;&lt;P&gt;// If the value matches the domain code, set the new column value to 1, otherwise set it to 0&lt;BR /&gt;if (targetValue == domainCod) {&lt;BR /&gt;featureResult[targetField + "_" + domainValue] = 1;&lt;BR /&gt;} else {&lt;BR /&gt;featureResult[targetField + "_" + domainValue] = 0;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Use a string to store the key (e.g., ObjectID or any unique identifier)&lt;BR /&gt;var objectID = Text(f["ObjectID"]);&lt;/P&gt;&lt;P&gt;// Add the modified feature result to the dictionary using the string key (ObjectID)&lt;BR /&gt;resultDict[objectID] = featureResult;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// Now, convert the dictionary back into a FeatureSet&lt;BR /&gt;var resultFeatures = [];&lt;BR /&gt;for (var key in resultDict) {&lt;BR /&gt;var fData = resultDict[key]; // Changed variable name from 'feature' to 'fData'&lt;BR /&gt;&lt;BR /&gt;// Create a new feature from the geometry and the updated attributes&lt;BR /&gt;var newFeature = Feature(geom); // Initialize a new feature with geometry&lt;BR /&gt;&lt;BR /&gt;// Set the fields for the new feature&lt;BR /&gt;for (var fieldName in fData) {&lt;BR /&gt;// Add the field and its value to the new feature&lt;BR /&gt;newFeature[fieldName] = fData[fieldName];&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Add the new feature to the result features list&lt;BR /&gt;resultFeatures.push(newFeature);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Create a FeatureSet from the result features array&lt;BR /&gt;var newFeatureSet = FeatureSet(resultFeatures);&lt;/P&gt;&lt;P&gt;// Return the new FeatureSet for use in the table widget&lt;BR /&gt;return newFeatureSet;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 04:22:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595032#M10872</guid>
      <dc:creator>EleanorCervigni</dc:creator>
      <dc:date>2025-03-13T04:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table with domains as columns</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595332#M10886</link>
      <description>&lt;P&gt;Can you give a better idea of what you'd like your final table to look like? Are you trying to get a summary of how many records are in the domains for each pair of fields? I'm guessing if your table looks like this&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;id&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;Field 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;Field2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;1&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 2&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;3&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 3&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;4&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;5&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;domain 1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;domain 2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you want your output table looking like this.&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;Field 2, domain 1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;Field 2, domain 2&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;Field 2, domain 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;Field 1, domain 1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;2&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;Field 1, domain 2&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;1&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="42.62295081967213%"&gt;Field 1, domain 3&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;0&lt;/TD&gt;&lt;TD width="19.041614123581336%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 19:04:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595332#M10886</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-03-13T19:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table with domains as columns</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595916#M10894</link>
      <description>&lt;P&gt;Yes thats it, the domains are different in each field. For clarity here is an example with some fake dataö&lt;/P&gt;&lt;P&gt;Original table&lt;/P&gt;&lt;TABLE width="231"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="64"&gt;ID&lt;/TD&gt;&lt;TD width="103"&gt;Report status&lt;/TD&gt;&lt;TD width="64"&gt;Suburb&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;submitted&lt;/TD&gt;&lt;TD&gt;perth&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;assigned&lt;/TD&gt;&lt;TD&gt;booragoon&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;finalised&lt;/TD&gt;&lt;TD&gt;booragoon&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;finalised&lt;/TD&gt;&lt;TD&gt;perth&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;assigned&lt;/TD&gt;&lt;TD&gt;armadale&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output table:&lt;/P&gt;&lt;TABLE width="329"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="98"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="103"&gt;Submitted&lt;/TD&gt;&lt;TD width="64"&gt;Assigned&lt;/TD&gt;&lt;TD width="64"&gt;Finalised&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Perth&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Booragoon&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Armadale&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 01:10:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1595916#M10894</guid>
      <dc:creator>EleanorCervigni</dc:creator>
      <dc:date>2025-03-17T01:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table with domains as columns</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1596277#M10901</link>
      <description>&lt;P&gt;Here's the script I came up with. It does your error checking, returning a table (InvalidTable function) with the error message if the featureset doesn't contain the fields or fields with domains. Since this could be a very memory-intensive code as it uses the Filter function for each combination of domains, I also include&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;'s &lt;A href="https://community.esri.com/t5/developers-questions/trying-to-optimize-arcade-script-to-fix-execution/m-p/1518421#M7196" target="_self"&gt;Memorize&lt;/A&gt; function to read the FeatureSet into memory.&lt;/P&gt;&lt;P&gt;Note that in my test, this used domains with a numeric code, so I used the description for its name (lines 111 and 121). If you use string codes, you can just use "key" and "ykey" instead of "xDomainMappings[key]" and "yDomainMappings[ykey]" in those lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function InvalidTable(message) {
  return FeatureSet(
    {
      fields: [{ alias: "error", name: "error", type: "esriFieldTypeString" }],
      geometryType: "",
      features: [{ attributes: { error: message } }]
    }
  );
}

function Memorize(fs) {
  var temp_dict = {
    fields: Schema(fs)["fields"],
    geometryType: "",
    features: []
  };
  for (var f in fs) {
    var attrs = {};
    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == "Date", Number(f[attr]), f[attr]);
    }
    Push(temp_dict["features"], { attributes: attrs });
  }
  return FeatureSet(temp_dict);
}

// Define the field to extract coded domains from
var targetFields = ["xAxisField", "xAxisField"]; //Change this to match the actual field names
var targetXField = targetFields[0]; 
var targetYField = targetFields[1];

var inputFS = FeatureSetByPortalItem(
  Portal("your portal"),
  "itemId",
  0,
  targetFields
);

// Check if the feature set is empty
if (IsEmpty(inputFS)) {
  return InvalidTable("Error: No features found in this dataset.");
}

// Get the schema for the layer to retrieve domain information
var fields = Schema(inputFS).fields;
var containsXTargetField = false;
var containsYTargetField = false;
var xDomainInfo;
var yDomainInfo;

// Loop through the schema fields to extract field names
for (var i = 0; i &amp;lt; Count(fields); i++) {
  var field = fields[i];
  if (field.name == targetXField) {
    containsXTargetField = true;
    // Retrieve the domain information for the XTarget field
    if (field.domain != null) xDomainInfo = field.domain;
  }
  if (field.name == targetYField) {
    containsYTargetField = true;
    // Retrieve the domain information for the YTarget field
    if (field.domain != null) yDomainInfo = field.domain;
  }
}

// Check if the target field exists in the list of field names
// If the field does not exist, return an error
if (!containsXTargetField)
  return InvalidTable(
    `Error: Field '${targetXField}' not found in the feature set.`
  );
if (!containsYTargetField)
  return InvalidTable(
    `Error: Field '${targetYField}' not found in the feature set.`
  );

// If no domain is found, return a message
if (IsEmpty(xdomainInfo))
  return InvalidTable(`Error: No domain found for field '${targetXField}'.`);
if (IsEmpty(ydomainInfo))
  return InvalidTable(`Error: No domain found for field '${targetYField}'.`);

// Create a dictionary of domain mappings (assumes it's a coded value domain)
var xDomainMappings = {};
if (xDomainInfo.type != "codedValue")
  return InvalidTable(
    `Error: Domain for field '${targetXField}' is not coded-value.`
  );
// If the domain type is coded value, we can extract the coded values and their descriptions
for (var i = 0; i &amp;lt; Count(xDomainInfo.codedValues); i++) {
  var codedValue = xDomainInfo.codedValues[i];
  xDomainMappings[`${codedValue.code}`] = codedValue.name;
}

var yDomainMappings = {};
if (yDomainInfo.type != "codedValue")
  return InvalidTable(
    `Error: Domain for field '${targetYField}' is not coded-value.`
  );
// If the domain type is coded value, we can extract the coded values and their descriptions
for (var i = 0; i &amp;lt; Count(yDomainInfo.codedValues); i++) {
  var codedValue = yDomainInfo.codedValues[i];
  yDomainMappings[`${codedValue.code}`] = codedValue.name;
}
console(xDomainMappings)
//Create the fields to hold the counts
var fieldList = [{ alias: "Domain", name: "Domain", type: "esriFieldTypeString" }];
for (var key in xDomainMappings) {
  Push(
    fieldList,
    { alias: xDomainMappings[key], name: key, type: "esriFieldTypeInteger" }
  );
}

//Store the fs in memory for multiple Filter calls
var fs = Memorize(inputFS);

//Loop through all the combinations of domains
var features = [];
for (var ykey in yDomainMappings) {
  var attributes = { Domain: yDomainMappings[ykey] };
  for (var xkey in xDomainMappings) {
    var query = `${targetXField} = @xkey AND ${targetyField} = @ykey`;
    attributes[xkey] = Count(Filter(fs, query));
    //console(`ykey: ${ykey}, xkey: ${xkey}: ${attributes[xkey]}`);
  }
  Push(features, { attributes: attributes });
}

var dict = { fields: fieldList, features: features };
return FeatureSet(dict);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I ran this on my data and got this table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snag_18c4ace.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/128082i5B3DFB29A0E93E23/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snag_18c4ace.png" alt="Snag_18c4ace.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tested these results using this GroupBy function,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return GroupBy(fs, targetFields, {name: "Count", expression: '1', statistic: 'Count'})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which gave me a table of the counts of each combination that was greater than zero.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snag_18e5217.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/128083i8E8FCF79F353CA55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snag_18e5217.png" alt="Snag_18e5217.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 19:41:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-a-table-with-domains-as-columns/m-p/1596277#M10901</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-03-17T19:41:02Z</dc:date>
    </item>
  </channel>
</rss>

