{"id":72802,"date":"2026-10-22T11:00:24","date_gmt":"2026-10-22T03:00:24","guid":{"rendered":"https:\/\/oihelp.corporate.ifs.com\/help\/?page_id=72802"},"modified":"2026-10-22T22:52:53","modified_gmt":"2026-10-22T14:52:53","slug":"aggregation","status":"publish","type":"page","link":"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/aggregation\/","title":{"rendered":"Aggregation"},"content":{"rendered":"<p class=\"intro-text\">Most reports don't need every row. They need counts, totals, latest dates and averages. OI OData can do that work on the server with $apply, so a dataset returns a handful of summary rows instead of thousands of raw ones.<\/p>\n\n<p class=\"left-bar\">This article applies to version 26R2 and later of IFS OI Explorer.<\/p>\n<h2 id=\"why-aggregate-on-the-server\" class=\"page-subheading\">Why aggregate on the server?<\/h2>\n<ul class=\"intro-text\">\n<li><strong>A dataset reads at most 1,000 rows.<\/strong> \"Entries per form per week\" might cover 50,000 entries, but only a few hundred groups.<\/li>\n<li><strong>It's faster.<\/strong> On database-backed objects, the grouping runs in SQL.<\/li>\n<li><strong>Your page stays simple.<\/strong> The table or chart shows the summary directly.<\/li>\n<\/ul>\n<h2 id=\"the-apply-pipeline\" class=\"page-subheading\">The $apply pipeline<\/h2>\n<p class=\"intro-text\">$apply is a series of steps separated by \/. Each step works on the output of the one before:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">$apply=filter(&lt;condition&gt;)\/compute(&lt;expression&gt; as &lt;alias&gt;)\/groupby((&lt;keys&gt;),aggregate(&lt;aggregates&gt;))<\/span><\/p>\n<table style=\"width: 100%; border-collapse: collapse; border: 1px solid #cccccc; margin: 15px 0 20px 0;\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">Step<\/th>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">filter(...)<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Keeps only the matching rows, like $filter<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">compute(... as Alias)<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Adds a calculated column<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">groupby((keys),aggregate(...))<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Groups rows and calculates one summary row per group<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">aggregate(...)<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Summarises the whole set into a single row<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"intro-text\">You can still add $orderby and $top after $apply. They work on the grouped result.<\/p>\n<hr \/>\n<h2 id=\"groupby-and-aggregate\" class=\"page-subheading\">groupby and aggregate<\/h2>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">groupby((Key1,Key2),aggregate(&lt;expression&gt; with &lt;method&gt; as &lt;Alias&gt;, ...))<\/span><\/p>\n<table style=\"width: 100%; border-collapse: collapse; border: 1px solid #cccccc; margin: 15px 0 20px 0;\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">Aggregate<\/th>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">Example<\/th>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">Result<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Count rows<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">$count as Events<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Number of rows in the group<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Sum<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">EntryCount with sum as Entries<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Total<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Average<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">OI.tonumber(Value) with average as AvgValue<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Mean<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Minimum<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">StartTime with min as FirstEvent<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Smallest or earliest<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Maximum<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Timestamp with max as LastSeen<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Largest or latest<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Count distinct<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">UserName with countdistinct as Users<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Number of different values<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">List text values<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Change with OI.stringagg as Changes<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">The group's values joined with <strong>,<\/strong>. Database-backed objects only. See <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/oi-query-functions\/#combining-text\">combining text<\/a>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"intro-text\">Events per monitor and severity in the last week, with the most recent:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">SentinelEvents?$apply=filter(StartTime ge OI.daysago(7))\/groupby((MonitorName,SeverityName),aggregate($count as Events,StartTime with max as Latest))&amp;$orderby=Events desc<\/span><\/p>\n<table style=\"width: 100%; border-collapse: collapse; border: 1px solid #cccccc; margin: 15px 0 20px 0;\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">MonitorName<\/th>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">SeverityName<\/th>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">Events<\/th>\n<th style=\"border: 1px solid #cccccc; padding: 6px 8px; text-align: left;\">Latest<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">THP Low<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">High<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">37<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">2026-10-06T22:15:00Z<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Compressor Trip<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">Critical<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">4<\/td>\n<td style=\"border: 1px solid #cccccc; padding: 6px 8px;\">2026-10-05T03:40:00Z<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"intro-text\">To summarise everything into one row, use aggregate without groupby:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">EntryRecords?$apply=filter(CreatedDate ge OI.daysago(30))\/aggregate($count as Entries,CreatedDate with max as Latest)<\/span><\/p>\n<hr \/>\n<h2 id=\"filter\" class=\"page-subheading\">filter<\/h2>\n<p class=\"intro-text\">filter(...) inside $apply takes the same conditions as $filter. Put it <strong>first<\/strong>, so the server groups as few rows as possible:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">TagDefinitions?$apply=filter(Datasource ne null)\/compute(Datasource\/Name as DatasourceName)\/groupby((DatasourceName),aggregate($count as Tags))&amp;$orderby=Tags desc<\/span><\/p>\n<hr \/>\n<h2 id=\"compute\" class=\"page-subheading\">compute<\/h2>\n<p class=\"intro-text\">compute(expression as Alias) adds a column you can group or aggregate on. Use it to:<\/p>\n<ul class=\"intro-text\">\n<li><strong>Group by a part of a date:<\/strong> compute(year(CreatedDate) as Yr,month(CreatedDate) as Mo)<\/li>\n<li><strong>Group by a related value<\/strong>, flat enough for a dataset: compute(Workspace\/Name as WorkspaceName)<\/li>\n<li><strong>Group by naming convention:<\/strong> compute(OI.nameprefix(Name) as Family)<\/li>\n<li><strong>Count conditionally:<\/strong> compute(OI.iif(CreatedDate ge OI.daysago(7),1,0) as ThisWeek), then ThisWeek with sum as RecentEntries<\/li>\n<li><strong>Convert text to a number:<\/strong> compute(OI.tonumber(Value) as Reading)<\/li>\n<\/ul>\n<p class=\"intro-text\">Entries created per day in September:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">EntryRecords?$apply=filter(CreatedDate ge 2026-09-01T00:00:00Z and CreatedDate lt 2026-10-01T00:00:00Z)\/compute(year(CreatedDate) as Year,month(CreatedDate) as Month,day(CreatedDate) as Day)\/groupby((Year,Month,Day),aggregate($count as Entries))&amp;$orderby=Year,Month,Day<\/span><\/p>\n<p class=\"intro-text\">Entries per form per week, for a logging-compliance chart:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">EntryForms?$apply=filter(Entry\/CreatedDate ge OI.monthsago(3))\/compute(OI.startofweek(Entry\/CreatedDate) as Week,FormSchema\/Name as Form)\/groupby((Week,Form),aggregate($count as Entries))&amp;$orderby=Week,Form<\/span><\/p>\n<p class=\"note\"><strong>Datasets need flat keys.<\/strong> Grouping directly on a related field, as in groupby((Workspace\/Name)), returns a nested object that a dataset can't read. Compute an alias first and group on the alias, as in the examples above.<\/p>\n<hr \/>\n<h2 id=\"compute-outside-apply\" class=\"page-subheading\">$compute outside $apply<\/h2>\n<p class=\"intro-text\">$compute adds calculated columns to ordinary, ungrouped rows. Select them like any other column:<\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">SentinelEvents?$filter=StartTime ge OI.daysago(7)&amp;$compute=OI.minutesbetween(StartTime,OI.ifnull(EndTime,now())) as Minutes&amp;$select=Entity,TestName,StartTime,Minutes&amp;$orderby=Minutes desc&amp;$top=100<\/span><\/p>\n<p class=\"intro-text\"><em>The 100 longest Sentinel events this week. Events that are still open count up to now.<\/em><\/p>\n<p class=\"intro-text\">Calculated columns can also be used in $filter and $orderby, as Minutes is used here.<\/p>\n<hr \/>\n<h2 id=\"sorting-and-limiting-grouped-results\" class=\"page-subheading\">Sorting and limiting grouped results<\/h2>\n<ul class=\"intro-text\">\n<li>$orderby can sort on group keys and aggregate aliases: &amp;$orderby=Events desc.<\/li>\n<li>$top limits the groups: &amp;$orderby=Events desc&amp;$top=10 gives the top 10.<\/li>\n<li>$orderby can't sort on a column that isn't in the grouped output.<\/li>\n<\/ul>\n<hr \/>\n<h2 id=\"worked-examples\" class=\"page-subheading\">Worked examples<\/h2>\n<p class=\"intro-text\"><strong>Top 10 workbook publishers<\/strong><\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">WorkbookPublishHistory?$apply=groupby((UserDisplayName),aggregate($count as Publishes))&amp;$orderby=Publishes desc&amp;$top=10<\/span><\/p>\n<p class=\"intro-text\"><strong>Number of assets per template family<\/strong><\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">TemplateInstances?$apply=filter(TemplateDefinition\/IsSystem eq false)\/compute(OI.nameprefix(TemplateDefinition\/Name) as Family)\/groupby((Family),aggregate($count as Assets))&amp;$orderby=Assets desc<\/span><\/p>\n<p class=\"intro-text\"><strong>Explorer users and when they were last seen<\/strong><\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">AnalyticsEventDetails?$apply=filter(UserName ne null and Timestamp ge OI.daysago(30))\/groupby((UserName),aggregate($count as Events,Timestamp with max as LastSeen))&amp;$orderby=Events desc<\/span><\/p>\n<p class=\"intro-text\"><strong>Open and recent entries in one pass<\/strong><\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">EntryRecords?$apply=compute(OI.iif(CreatedDate ge OI.daysago(7),1,0) as ThisWeek)\/groupby((State),aggregate($count as Entries,ThisWeek with sum as RecentEntries))<\/span><\/p>\n<p class=\"intro-text\"><strong>Sentinel events by weekday, last quarter<\/strong><\/p>\n<p><span style=\"font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 12px; background-color: #eeeeee; padding: 2px 5px; line-height: 1.35;\">SentinelEvents?$apply=filter(StartTime ge OI.monthsago(3))\/compute(OI.weekday(StartTime) as Day)\/groupby((Day),aggregate($count as Events))&amp;$orderby=Day<\/span><\/p>\n<hr \/>\n<h2 id=\"things-to-know\" class=\"page-subheading\">Things to know<\/h2>\n<ul class=\"intro-text\">\n<li><strong>Aggregate on database-backed objects.<\/strong> On live objects (SapiCases, Tags, Templates and others), $apply is evaluated over at most 5,000 source rows. On database-backed objects (EntryRecords, TagDefinitions, Entities, SentinelEvents and others), it runs in SQL over every row. See <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/limits-and-performance\/\">Limits and Performance<\/a>.<\/li>\n<li><strong>Dynamic entry fields keep their type<\/strong>, so sum and average work on number fields of SapiCases, SapiIssues, SapiSummaries and SapiTimeWindows, over at most 5,000 entries.<\/li>\n<li><strong>$count is a keyword<\/strong>, written exactly as $count as Alias.<\/li>\n<li><strong>Aliases are case-sensitive<\/strong> and must be unique within the query.<\/li>\n<\/ul>\n<hr \/>\n<p class=\"left-bar\"><strong>Next:<\/strong> <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/combining-data\/\">Combining Data<\/a><\/p>\n<p class=\"left-bar\"><strong>Related:<\/strong> <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/oi-query-functions\/\">OI Query Functions<\/a> \u00b7 <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/writing-queries\/\">Writing Queries<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most reports don't need every row. They need counts, totals, latest dates and averages. OI OData can do that work on the server with $apply, so a dataset returns a handful of summary rows instead of thousands of raw ones. This article applies to version 26R2 and later of IFS\u2026<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"https:\/\/oihelp.corporate.ifs.com\/help\/oi-odata\/aggregation\/\">Read more<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":38,"featured_media":0,"parent":72744,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-72802","page","type-page","status-publish","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/72802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/comments?post=72802"}],"version-history":[{"count":6,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/72802\/revisions"}],"predecessor-version":[{"id":72913,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/72802\/revisions\/72913"}],"up":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/72744"}],"wp:attachment":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media?parent=72802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/categories?post=72802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/tags?post=72802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}