Skip to main content
Skip table of contents

5. Aggregate, Merge, and f(x)

In this Session…

Before you begin…

  • Using Transforms:

    • f(x) and Link to reformat and reorganize data.

    • Aggregate to enumerate and/or evaluate nodes or edges.

    • Merge to merge nodes or edges.

To follow along, download the files:




How To GraphXR 5. Aggregate and Merge


Before You Begin…

Ideally, you’ll have worked through Module 4. Link and Filter. If you’re starting here, and you want to follow along, you’ll need to:

  • Log in to GraphXR, create a Project, and open its graph space. 

  • Download the file, which contains the Game of Thrones data we’ll use in our tutorials.

  • Drag and drop the file HowTo_05_START.graphxr onto the space.


So far, we’ve extracted House nodes from Characters.csv data, created  BELONGS_TO edges connecting them with Character nodes, created Lines nodes, and SPOKE edges connecting Characters nodes to the Lines they spoke.


Now we’ll use Merge and Aggregate transforms to link lines of dialogue with the broadcast episodes they were spoken on. Drag and drop Episodes.csv onto the graph space to create the nodes of a new Episodes category.


The Episodes.csv file contains the titles, descriptions, air dates, episode numbers, season numbers, and viewership for each broadcast episode. We’ll now connect lines of dialog to corresponding episodes.


We have a little problem, though. In Lines, season and episode number are combined into the single string called seasonEpisode. In Episodes, they occupy separate properties. To fix this, we’ll use a transform to generate a new seasonEpisode property on our Episode nodes. Open the Transform panel and f(x) tab.


The f(x) transforms let us run javascript formulas on properties of a category or relationship, and place the result in a new (or existing) property. First, select the Episodes category and episodeNumber property from the dropdown menus.


Choose toCustom, since we’ll need to enter a custom formula (rather than one of the preset formulas). Enter seasonEpisode as the new property name.


Enter the custom formula:

(propVal,props) => 'S'+props.seasonNumber+'E'+props.episodeNumber

An example result is automatically displayed under the New Property Name


Click Run and scroll to the bottom of the panel to view the results. Now that we have property values that match, we’ll link Episodes and Lines nodes.


Open the Link tab and choose Lines as the source category, Episodes as the target category, and enter SPOKEN_ON as the new relationship. Select seasonEpisode as the source and target property, and click Run.


The graph now reveals connections and properties we can explore further. Take a Snapshot, and then we’ll use Aggregate to add new properties based on existing ones, and Merge to simplify the graph.


Let’s find the number of lines per episode. Lines nodes have a lineCount property for each speaker and episode. With the Aggregate transform, we’ll sum those values and write the total to a new totalLines property on connected Episode nodes.


Go to the Transform panel and Aggregate tab. 
Under Aggregate to Category, select Episodes.
Under Aggregate Along select SPOKEN_ON (the relationship connecting Lines to Episodes nodes).


Click Property from Neighbor Nodes, and select lineCount.
Under New Property enter totalLines, select the sum preset, and click Run.


Let’s also use Aggregate to calculate the number of unique characters per episode. Again, select the Episodes category and SPOKEN_ON relationship.


Click Property from Neighbor Nodes, and select the speaker property. Under New Property enter totalCharacters, under Formula Name select count, and click Run.


Now display a table to see the new totalLines and totalCharacters properties.
And before we move on, create another Snapshot.
Note that at any time, you can download your snapshots as a single .ZIP archive.


Now let’s simplify the graph using Merge. It combines nodes of a single category or the edges of a single relationship based on a property value. We’ll use the seasonEpisode property to merge Lines nodes for an episode into a single node.


Go to the Transform panel and Merge tab.
Click Category and select Lines, and select the seasonEpisode property.
Click Clear Unselected Properties since only the seasonEpisode property is meaningful.


Now click Run. With only one Lines node per Episode, the simplified graph now clarifies connections between Episodes, Characters, and Lines of dialogue.


Save a data view, take a snapshot, and download the snapshot archive.
Next, in Module 6. Shortcut, we’ll return to the snapshot we created before merging to simplify the graph even further.

Next Steps…

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.