Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Thomasowich
Contributor II
Contributor II

How do I aggregate total data to a dimension based on a dynamic condition?

I have a table consisting of three columns: Location, Date, Value. Each location appears exactly once.

I want to add a new column Aggr which for each location adds up Value of all other locations whose date is higher than its own date. Here is an example:

Location Date Value Aggr
USA 01.01.2022 1 10
Germany 03.03.2022 2 0
Japan 01.01.2021 4 11
China 02.02.2022 8 2

 

How do I do this in Qlik?

Labels (1)
1 Reply
maxgro
MVP
MVP

try with


T:
LOAD * INLINE [
Location, Date, Value, Aggr
USA, 01.01.2022, 1, 10
Germany, 03.03.2022, 2, 0
Japan, 01.01.2021, 4, 11
China, 02.02.2022, 8, 2
];

JOIN (T)
LOAD Location as Location1,
Date as Date1,
Value as Value1
RESIDENT T;

Z:
LOAD Location,
Date,
ONLY(Value) as Value,
ONLY(Aggr) as Aggr,
SUM(IF(Date1>Date, Value1)) as NewAggr
RESIDENT T
WHERE Date1 >= Date
GROUP BY Location, Date
;

DROP TABLE T;

 

maxgro_0-1673470155621.png