Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
markgraham123
Specialist
Specialist

Calculate Distinct value of Rangesum

Hi All,

I want to calculate Rangesum for below column 'Weight' taking in the distinct value of order.

Code i'm using gives me Range sum by counting same value multiple times:

If(Zone= Previous(Zone) and Time = Previous(Time), RangeSum(Cum_Wt, Peek('Cum_Wt')), Weight) as Cum_Wt

Current O/P : 280

Desired Output : 70

Here is the sample data:

Can someone please help on how can i only Rangesum Weight of an Order only once?

TimeZoneOrderSKUWeight
7B78956471A10
7B78956472B10
7B78956472A10
7B78956472C10
8B87631903D20
8B87631903A20
8B87631904B20
8B87631905E20
9C76418391B25
9C76418394D25
9C76418393D25
9C76418391K25
10D85661282J15
10D85661282P15
10D85661285T15
10D85661288U15

 

Any help is highly appreciated.

Labels (3)
1 Solution

Accepted Solutions
sunny_talwar

Table:
LOAD * INLINE [
    Time, Zone, Order, SKU, Weight
    7, B, 7895647, 1A, 10
    7, B, 7895647, 2B, 10
    7, B, 7895647, 2A, 10
    7, B, 7895647, 2C, 10
    8, B, 8763190, 3D, 20
    8, B, 8763190, 3A, 20
    8, B, 8763190, 4B, 20
    8, B, 8763190, 5E, 20
    9, C, 7641839, 1B, 25
    9, C, 7641839, 4D, 25
    9, C, 7641839, 3D, 25
    9, C, 7641839, 1K, 25
    10, D, 8566128, 2J, 15
    10, D, 8566128, 2P, 15
    10, D, 8566128, 5T, 15
    10, D, 8566128, 8U, 15
];

FinalTable:
LOAD *,
	 If(Time = Previous(Time) and Zone = Previous(Zone), Peek('Cum_Wt'), RangeSum(Peek('Cum_Wt'), Weight)) as Cum_Wt
Resident Table
Order By Time, Zone;

DROP Table Table;

View solution in original post

4 Replies
markgraham123
Specialist
Specialist
Author

sunny_talwar

The code you showed is not going to give you a single value... it will show a value on each row... I am not sure if you want a single value or row for each value here?

markgraham123
Specialist
Specialist
Author

Here is the desired output in the last column, Sunny...

 

TimeZoneOrderSKUWeightCum_Wt
7B78956471A1010
7B78956472B1010
7B78956472A1010
7B78956472C1010
8B87631903D2030
8B87631903A2030
8B87631904B2030
8B87631905E2030
9C76418391B2555
9C76418394D2555
9C76418393D2555
9C76418391K2555
10D85661282J1570
10D85661282P1570
10D85661285T1570
10D85661288U1570
sunny_talwar

Table:
LOAD * INLINE [
    Time, Zone, Order, SKU, Weight
    7, B, 7895647, 1A, 10
    7, B, 7895647, 2B, 10
    7, B, 7895647, 2A, 10
    7, B, 7895647, 2C, 10
    8, B, 8763190, 3D, 20
    8, B, 8763190, 3A, 20
    8, B, 8763190, 4B, 20
    8, B, 8763190, 5E, 20
    9, C, 7641839, 1B, 25
    9, C, 7641839, 4D, 25
    9, C, 7641839, 3D, 25
    9, C, 7641839, 1K, 25
    10, D, 8566128, 2J, 15
    10, D, 8566128, 2P, 15
    10, D, 8566128, 5T, 15
    10, D, 8566128, 8U, 15
];

FinalTable:
LOAD *,
	 If(Time = Previous(Time) and Zone = Previous(Zone), Peek('Cum_Wt'), RangeSum(Peek('Cum_Wt'), Weight)) as Cum_Wt
Resident Table
Order By Time, Zone;

DROP Table Table;