Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
stantrolav
Partner - Creator II
Partner - Creator II

Hierarchy scripting Child, Parent, Level of parent (Depth?)

Hello my dear solver of logic puzzles. Could you help me with something special?

In attachment you'll find file with 3 columns. From these 3 columns you must make table with maximum number in row [Level of parent]. Row [Name] is the name of cell in new table. [Parent] is "parent" cell for [Name]/ And Level is Number of column in our new table for Parent cell.

Have you understood this? Well, I need to make hierarchy. Help .

1 Solution

Accepted Solutions
stantrolav
Partner - Creator II
Partner - Creator II
Author

I got answer.

a:

Load *,

Name as Key;

LOAD  Name,

      Parent,

      Level

FROM

Data.qvd

(qvd);

// Выстроим иерархию

Verdict:

Load Distinct

Max(Level) as TheMostMaxLevel

Resident a;

LET varLevel = 1;

LET varLevelMax = peek('TheMostMaxLevel',0,'Verdict');

  LET varLevelDimName = 'Dim' & $(varLevel);

  LET varLevelDimNameNext = 'Dim' & ($(#varLevel) + 1);

  Aggregation:

  LOAD

  Name as Key,

  Parent as $(varLevelDimName)

  Resident a

  Where Level = $(#varLevel);

  LET varLevel = $(varLevel) + 1;

  For i = 2 to $(varLevelMax) step 1

  LET varLevelDimName = 'Dim' & $(varLevel);

  left Join (Aggregation)

  LOAD

  Name as Key,

  Parent as $(varLevelDimName)

  Resident a

  Where Level = $(#varLevel);

  LET varLevel = $(varLevel) + 1;

  NEXT i;

drop Table Verdict;

View solution in original post

2 Replies
Not applicable

Stanislaw,

may you provide few rows of input and output table for this input?

regards

D

stantrolav
Partner - Creator II
Partner - Creator II
Author

I got answer.

a:

Load *,

Name as Key;

LOAD  Name,

      Parent,

      Level

FROM

Data.qvd

(qvd);

// Выстроим иерархию

Verdict:

Load Distinct

Max(Level) as TheMostMaxLevel

Resident a;

LET varLevel = 1;

LET varLevelMax = peek('TheMostMaxLevel',0,'Verdict');

  LET varLevelDimName = 'Dim' & $(varLevel);

  LET varLevelDimNameNext = 'Dim' & ($(#varLevel) + 1);

  Aggregation:

  LOAD

  Name as Key,

  Parent as $(varLevelDimName)

  Resident a

  Where Level = $(#varLevel);

  LET varLevel = $(varLevel) + 1;

  For i = 2 to $(varLevelMax) step 1

  LET varLevelDimName = 'Dim' & $(varLevel);

  left Join (Aggregation)

  LOAD

  Name as Key,

  Parent as $(varLevelDimName)

  Resident a

  Where Level = $(#varLevel);

  LET varLevel = $(varLevel) + 1;

  NEXT i;

drop Table Verdict;