<?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 table with sums for columns in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680003#M232455</link>
    <description>&lt;P&gt;Assuming these are separate events and that you have or can extract the fields from your event data, try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart sum('total-received') as total over 'entity-id' by 'message-name'&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 07 Mar 2024 23:04:47 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2024-03-07T23:04:47Z</dc:date>
    <item>
      <title>Create table with sums for columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/679980#M232448</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;we have a log that contains the amount of times any specific message has been sent by the user in every session. This log contains the user's ID (data.entity-id), the message ID (data.message-code), message name (data.message-name) and the total amount of times it was sent during each session (data.&lt;SPAN&gt;total-received).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I'm trying to create a table where the 1st column shows the User's ID (data.entity-id), then each column shows the&amp;nbsp; sum of the total amount of times each message type (data.&lt;SPAN&gt;total-received) was received. Ideally I would be able to create a dashboard were I can have a list of the&amp;nbsp;data.message-code's I want to be used as columns.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Example data:&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data: {
     entity-id: 1
     message-code: 445
     message-name: handshake
     total-received: 10
   }

data: {
     entity-id: 1
     message-code: 269
     message-name: switchPlayer
     total-received: 20
   }

data: {
     entity-id: 1
     message-code: 269
     message-name: switchPlayer
     total-received: 22
   }

  data: {
     entity-id: 2
     message-code: 445
     message-name: handshake
     total-received: 12
   }

data: {
     entity-id: 2
     message-code: 269
     message-name: switchPlayer
     total-received: 25
   }

data: {
     entity-id: 2
     message-code: 269
     message-name: switchPlayer
     total-received: 30
   }&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Ideally the table would look like this:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;Entity-id | &lt;SPAN class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;handshake&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; | &lt;SPAN class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;switchPlayer&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
    1     |    10     |     42
    2     |    12     |     55&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Is this possible? What would be the best way to store the message-code in a dashboard? &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 23:51:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/679980#M232448</guid>
      <dc:creator>RubenAcon</dc:creator>
      <dc:date>2024-03-07T23:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create table with sums for columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680003#M232455</link>
      <description>&lt;P&gt;Assuming these are separate events and that you have or can extract the fields from your event data, try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart sum('total-received') as total over 'entity-id' by 'message-name'&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Mar 2024 23:04:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680003#M232455</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-03-07T23:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create table with sums for columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680004#M232456</link>
      <description>&lt;P&gt;Assuming these are separate events and the fields are auto extracted JSON fields, then this statement will give you your table&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... your search ...
| chart sum("data.total-received") over data.entity-id by data.message-name&lt;/LI-CODE&gt;&lt;P&gt;As for having a dropdown where you can choose the message codes you want to display, have a multiselect input and use a populating search that does&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... your search ...
| stats count by data.message-name&lt;/LI-CODE&gt;&lt;P&gt;and use the field for label/field for value settings to assign the name.&lt;/P&gt;&lt;P&gt;You will have to work out the tokenisation to that in your search for the data to show in the table you can filter out the ones you want.&lt;/P&gt;&lt;P&gt;Also, you could use a single base search to drive the population of the dropdown as well as the results for the table, which would improve your dashboard load times, but I'll leave that as an exercise for you to play with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 23:11:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680004#M232456</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-03-07T23:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create table with sums for columns</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680005#M232457</link>
      <description>&lt;P&gt;If I read your samples right, each of that "data" block is its own event. &amp;nbsp;Is this correct? (By the way, you would help volunteers and yourself greatly if you post sample/mock data in raw text format which is JSON compliant; Splunk's beautified display is not.) &amp;nbsp;In that case, Splunk would have given you three fields of your interest: &lt;FONT face="courier new,courier"&gt;data.entity_id&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;data.message-name&lt;/FONT&gt;, and &lt;FONT face="courier new,courier"&gt;data.total-received&lt;/FONT&gt;. &amp;nbsp;Do you get these?&lt;/P&gt;&lt;P&gt;Assuming both assumptions are correct,&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xyseries" target="_blank" rel="noopener"&gt;xyseries&lt;/A&gt;&amp;nbsp;is your friend, like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats sum(data.total-received) as subtotal by data.message-name data.entity-id
| xyseries "data.entity-id" "data.message-name" subtotal&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your mock events give you&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;data-entity-id&lt;/TD&gt;&lt;TD&gt;handshake&lt;/TD&gt;&lt;TD&gt;switchPlayer&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;42&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Note, I reconstructed JSON compliant events as the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "data": {
     "entity-id": 1,
     "message-code": 445,
     "message-name": "handshake",
     "total-received": 10
   }
}

{
  "data": {
     "entity-id": 1,
     "message-code": 269,
     "message-name": "switchPlayer",
     "total-received": 20
   }
}

{
  "data": {
     "entity-id": 1,
     "message-code": 269,
     "message-name": "switchPlayer",
     "total-received": 22
   }
}

  {
  "data": {
     "entity-id": 2,
     "message-code": 445,
     "message-name": "handshake",
     "total-received": 12
   }
}

{
  "data": {
     "entity-id": 2,
     "message-code": 269,
     "message-name": "switchPlayer",
     "total-received": 25
   }
}

{
  "data": {
     "entity-id": 2,
     "message-code": 269,
     "message-name": "switchPlayer",
     "total-received": 30
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an emulation you can play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = split("{
  \"data\": {
     \"entity-id\": 1,
     \"message-code\": 445,
     \"message-name\": \"handshake\",
     \"total-received\": 10
   }
}

{
  \"data\": {
     \"entity-id\": 1,
     \"message-code\": 269,
     \"message-name\": \"switchPlayer\",
     \"total-received\": 20
   }
}

{
  \"data\": {
     \"entity-id\": 1,
     \"message-code\": 269,
     \"message-name\": \"switchPlayer\",
     \"total-received\": 22
   }
}

  {
  \"data\": {
     \"entity-id\": 2,
     \"message-code\": 445,
     \"message-name\": \"handshake\",
     \"total-received\": 12
   }
}

{
  \"data\": {
     \"entity-id\": 2,
     \"message-code\": 269,
     \"message-name\": \"switchPlayer\",
     \"total-received\": 25
   }
}

{
  \"data\": {
     \"entity-id\": 2,
     \"message-code\": 269,
     \"message-name\": \"switchPlayer\",
     \"total-received\": 30
   }
}", "

")
| mvexpand data
| rename data AS _raw
| spath
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 23:20:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-table-with-sums-for-columns/m-p/680005#M232457</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-03-07T23:20:26Z</dc:date>
    </item>
  </channel>
</rss>

