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

Announcements
AWS Degraded - You may experience Community slowness, timeouts, or trouble accessing: LATEST HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
xyz_1011
Partner - Creator II
Partner - Creator II

Scripting Question

Hi all,

the following is an extract of my data:

Contract Period Discount Discount To Be
1234 2023-Q3 10 10
1234 2023-Q4 15 15

1234

2024-Q1   15
12 2023-Q3 25 25
12 2023-Q4   25
12 2024-Q1   25
12 2024-Q2 15 15

 

There are cases, where Discount is not populated. In these cases i (always) want to take the Discount of the last Period for a given Contract. I have tried Previous() but that only appears to be working for cases like contract 1234 (one missing record only), but it does not seem to work for Contracts with multiple gaps (like contract 12)

Any hints and help is much appreciated. Thanks!

Labels (1)
1 Solution

Accepted Solutions
LRuCelver
Partner - Creator III
Partner - Creator III

Assuming the first entry for ever contract always has a Discount, you can use this:

 

//	Load Data and format '' to Null
Data:
NoConcatenate Load
	Contract,
    Period,
    If(Discount <> '', Discount) as Discount,
    "Discount To Be"	
Inline [
    Contract,	Period,		Discount,	Discount To Be
    1234,		2023-Q3,	10,			10
    1234,		2023-Q4,	15,			15
    1234,		2024-Q1,	,			15
    12,			2023-Q3,	25,			25
    12,			2023-Q4,	,			25
    12,			2024-Q1,	,			25
    12,			2024-Q2,	15,			15
];

//	Fill missing Discounts
Final:
NoConcatenate Load
	Contract,
    Period,
    If(IsNull(Discount), Peek('Discount'), Discount) as Discount,
    "Discount To Be"
Resident Data
Order By Contract, Period;

Drop Table Data;

 

View solution in original post

1 Reply
LRuCelver
Partner - Creator III
Partner - Creator III

Assuming the first entry for ever contract always has a Discount, you can use this:

 

//	Load Data and format '' to Null
Data:
NoConcatenate Load
	Contract,
    Period,
    If(Discount <> '', Discount) as Discount,
    "Discount To Be"	
Inline [
    Contract,	Period,		Discount,	Discount To Be
    1234,		2023-Q3,	10,			10
    1234,		2023-Q4,	15,			15
    1234,		2024-Q1,	,			15
    12,			2023-Q3,	25,			25
    12,			2023-Q4,	,			25
    12,			2024-Q1,	,			25
    12,			2024-Q2,	15,			15
];

//	Fill missing Discounts
Final:
NoConcatenate Load
	Contract,
    Period,
    If(IsNull(Discount), Peek('Discount'), Discount) as Discount,
    "Discount To Be"
Resident Data
Order By Contract, Period;

Drop Table Data;