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: 
urazbekov
Contributor
Contributor

new values (calculations) depending on hierarchy

Hello everyone, 

 

I met with a challenge to calculate new values depending on values of subcategory. 

In original, I have such a table

БВ1
1.0А00-Т988900
2.0А00-В991140
2.1В16.0-В17.85
2.2В18.0-В19.9455
3.0С00-D483500
3.1D10-D362600

 

So, here we see that group 1.0 includes values of 2.0 and 3.0, and 2.0 includes 2.1 and 2.2. In the end I would like to get new values of 1.0 (what remains without 2.0 and 3.0), 2.0 (what remains without 2.1 and 2.2) and others, like in the following table: 

БВ12comment for calculations
1.0А00-Т98890042608900 - 1140 - 3500
2.0А00-В9911406801140 - 5 - 455
2.1В16.0-В17.8555
2.2В18.0-В19.9455455455
3.0С00-D4835009003500 - 2600
3.1D10-D36260026002600

 

Hope to see your suggestions. 

 

Thank you! 

Labels (1)
1 Reply
chrismarlow
Specialist II
Specialist II

Hi,

A bit messy, but try this;

data:
LOAD * INLINE [
Б,В,1
1,А00-Т98,8900
2,А00-В99,1140
2.1,В16.0-В17.8,5
2.2,В18.0-В19.9,455
3,С00-D48,3500
3.1,D10-D36,2600
];

left join (data)
Load
	1 as Б,
	Sum([1]) as sub_from_1
Resident data
Where Б<>1 and Floor(Б,1)=Б
Group By 1;

left join (data)
Load
	Floor(Б,1) as Б,
	Sum([1]) as sub_from_int
Resident data
Where Б<>1 and Floor(Б,1)<>Б
Group By Floor(Б,1);

data_final:
NoConcatenate
Load
	Б,
	В,
	[1],
	[1]-If(isnull(sub_from_1),0,sub_from_1)-If(isnull(sub_from_int),0,sub_from_int)as [2]
resident data;

DROP TABLE data;

Cheers,

Chris.