Skip to main content Skip to complementary content

HierarchyBelongsTo

This prefix is used to transform a hierarchy table to a table that is useful in a Qlik Sense data model. It can be put in front of a LOAD or a SELECT statement and will use the result of the loading statement as input for a table transformation.

Syntax:  

HierarchyBelongsTo (NodeID, ParentID, NodeName, AncestorID, AncestorName, [DepthDiff])(loadstatement | selectstatement)

 

The input table must be an adjacent nodes table. Adjacent nodes tables are tables where each record corresponds to a node and has a field that contains a reference to the parent node. In such a table the node is stored on one record only but the node can still have any number of children. The table may of course contain additional fields describing attributes for the nodes.

The prefix creates a table containing all ancestor-child relations of the hierarchy. The ancestor fields can then be used to select entire trees in the hierarchy. The output table in most cases contains several records per node.

An additional field containing the depth difference of the nodes can be created.

Arguments:  

Argument Description
NodeID The name of the field that contains the node id. This field must exist in the input table.
ParentID The name of the field that contains the node id of the parent node. This field must exist in the input table.
NodeName The name of the field that contains the name of the node. This field must exist in the input table.
AncestorID A string used to name the new ancestor id field, which contains the id of the ancestor node.
AncestorName A string used to name the new ancestor field, which contains the name of the ancestor node.
DepthDiff A string used to name the new DepthDiff field, which contains the depth of the node in the hierarchy relative the ancestor node. Optional parameter. If omitted, this field will not be created.

Example:  

HierarchyBelongsTo (NodeID, ParentID, Node, Tree, ParentName) LOAD
       NodeID,

       ParentID,

       NodeName

       From data.xls (biff, embedded labels, table is [Sheet1$];

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!