Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Qlik Experts,
I have the following table (Sample Data) :
Code | Account Number | Quantity | Stock | Date | Type | Value |
---|---|---|---|---|---|---|
A01 | 00126 | 6000 | 5500 | 05/15/2018 | 100 | 11000 |
A01 | 00126 | 3000 | 5500 | 04/21/2018 | 100 | 11000 |
A01 | 00126 | 1500 | 5500 | 02/03/2017 | 100 | 11000 |
A11 | 00243 | 7000 | 8200 | 03/03/2018 | 100 | 4100 |
A11 | 00243 | 3000 | 8200 | 03/01/2018 | 100 | 4100 |
A11 | 00245 | 1000 | 8200 | 12/23/2014 | 100 | 4100 |
A11 | 00243 | 5000 | 8200 | 02/23/2014 | 100 | 4100 |
A11 | 00243 | 4000 | 8200 | 02/02/2014 | 100 | 4100 |
A55 | 00455 | 9000 | 15000 | 11/13/2017 | 100 | 5000 |
A55 | 00455 | 17000 | 15000 | 1/13/2017 | 100 | 5000 |
B10 | 01666 | 3000 | 1500 | 05/23/2018 | 100 | 9000 |
B10 | 01666 | 2000 | 1500 | 03/03/2018 | 100 | 9000 |
B10 | 01700 | 1500 | 1500 | 01/23/2017 | 100 | 9000 |
B10 | 01700 | 7000 | 1500 | 01/03/2017 | 100 | 9000 |
C41 | 00300 | 1000 | 350 | 02/14/2016 | 100 | 3500 |
C41 | 00300 | 40 | 350 | 01/05/2016 | 100 | 3500 |
C41 | 00300 | 100 | 350 | 12/22/2015 | 100 | 3500 |
E03 | 00026 | 6000 | 5000 | 03/01/2018 | 100 | 7500 |
F22 | 05622 | 100 | 750 | 12/17/2017 | 100 | 1500 |
F22 | 05625 | 800 | 750 | 12/17/2016 | 100 | 1500 |
H20 | 00666 | 25000 | 10000 | 05/15/2018 | 100 | 250 |
H20 | 00666 | 3000 | 10000 | 04/15/2018 | 100 | 250 |
H20 | 00666 | 17000 | 10000 | 03/15/2018 | 100 | 250 |
H20 | 00666 | 55000 | 10000 | 02/15/2018 | 100 | 250 |
H20 | 00666 | 2300 | 10000 | 01/15/2018 | 100 | 250 |
H20 | 00666 | 1500 | 10000 | 1/13/2018 | 100 | 250 |
K15 | 12268 | 300 | 2500 | 05/07/2018 | 100 | 2500 |
K15 | 12268 | 1300 | 2500 | 04/22/2018 | 100 | 2500 |
K15 | 12268 | 500 | 2500 | 03/25/2018 | 100 | 2500 |
K15 | 12268 | 1000 | 2500 | 12/7/2017 | 100 | 2500 |
L01 | 14760 | 500 | 2000 | 05/04/2018 | 100 | 2200 |
L01 | 14760 | 250 | 2000 | 05/02/2018 | 100 | 2200 |
L01 | 14760 | 450 | 2000 | 04/04/2018 | 100 | 2200 |
L01 | 14760 | 300 | 2000 | 02/14/2018 | 100 | 2200 |
L01 | 14760 | 1000 | 2000 | 02/10/2018 | 100 | 2200 |
These are values of multiple Tables combined into a single table (Stock Value is Multiplied on account of Joining of 2 Tables).
The 'Value Field' and 'Stock Field' are related to each other
I have to calculate Ageing as per the following (Today = 05/31/2018, 'MM/DD/YY') :
The Date Field has to be sorted in Descending order w.r.t. Code
So My Output should be the following:
Code | Account Number | Stock | Type | Value | 0-30 Days Stock | 31-60 Days Stock | 61-90 Days Stock | 91-120 Days Stock | 121-150 Days Stock | 151-180 Days Stock | 181-270 Days Stock | 271-365 Days Stock | 366-730 Days Stock | 730+ Days Stock | 0-30 Days Value | 31-60 Days value | 61-90 Days Value | 91-120 Days Value | 121-150 Days Value | 151-180 Days Value | 181-270 Days Value | 271-365 Days Value | 366-730 Days Value | 730+ Days Value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A01 | 00126 | 5500 | 100 | 11000 | 5500 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
A11 | 00243 | 8200 | 100 | 4100 | 0 | 7000 | 0 | 1200 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3500 | 0 | 600 | 0 | 0 | 0 | 0 | 0 | 0 |
A55 | 00455 | 15000 | 100 | 5000 | 0 | 0 | 0 | 0 | 0 | 0 | 9000 | 0 | 6000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3000 | 0 | 2000 | 0 |
B10 | 01666 | 1500 | 100 | 9000 | 1500 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
C41 | 00300 | 350 | 100 | 3500 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 350 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3500 |
E03 | 00026 | 5000 | 100 | 7500 | 0 | 0 | 0 | 0 | 5000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7500 | 0 | 0 | 0 | 0 | 0 |
F22 | 05622 | 750 | 100 | 1500 | 0 | 0 | 0 | 0 | 0 | 100 | 0 | 0 | 650 | 0 | 0 | 0 | 0 | 0 | 0 | 200 | 0 | 0 | 1300 | 0 |
H20 | 00666 | 10000 | 100 | 250 | 10000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 250 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
K15 | 12268 | 2500 | 100 | 2500 | 300 | 1300 | 500 | 0 | 0 | 400 | 0 | 0 | 0 | 0 | 300 | 1300 | 500 | 0 | 0 | 400 | 0 | 0 | 0 | 0 |
L01 | 14760 | 2000 | 100 | 2200 | 750 | 450 | 0 | 800 | 0 | 0 | 0 | 0 | 0 | 0 | 825 | 495 | 0 | 880 | 0 | 0 | 0 | 0 | 0 | 0 |
I am attaching this on an Excel Sheet as well (Input and Output) for further Reference.
Thanks In Advance.
PFA
I think you added some of the buckets as dimensions instead of expressions. After removing, I get this
Also try with this script
Table:
LOAD
Code,
"Account Number",
Quantity,
Stock,
"Date",
"Type",
Value
FROM [lib://Lib/Sheet For Buckets.xlsx]
(ooxml, embedded labels, table is Input);
FinalTable:
LOAD *,
if(Today() - "Date" <= 30, Temp2,'0') as [0-30 Days],
if(Today() - "Date" > 30 and Today() - "Date" <= 60, Temp2,'0') as [31-60 Days],
if(Today() - "Date" > 60 and Today() - "Date" <= 90, Temp2,'0') as [61-90 Days],
if(Today() - "Date" > 90 and Today() - "Date" <= 120, Temp2,'0') as [91-120 Days],
if(Today() - "Date" > 120 and Today() - "Date" <= 180, Temp2,'0') as [121-180 Days],
if(Today() - "Date" > 180 and Today() - "Date" <= 270, Temp2,'0') as [181-270 Days],
if(Today() - "Date" > 270 and Today() - "Date" <= 365, Temp2,'0') as [271-365 Days],
if(Today() - "Date" > 365, Temp2,'0') as [>365 Days];
LOAD *,
If(Code = Previous(Code),
If(Peek('Temp1') < 0, If(Temp1 > 0, Stock - Peek('CumQuantity'), Quantity), 0),
If(Temp1 > 0, Stock, Quantity)) as Temp2;
LOAD *,
If(Code = Previous(Code), RangeSum(Peek('CumQuantity'), Quantity), Quantity) as CumQuantity,
If(Code = Previous(Code), RangeSum(Peek('CumQuantity'), Quantity), Quantity) - Stock as Temp1
// Replace(Class(Today() - Date, 30), ' <= x < ', '-') as Buckets
Resident Table
Order By Code, Date desc;
DROP Table Table;
Dim:
LOAD * INLINE [
Dim
1
2
];
The Results are Coming for Stock correctly, but not for Values ??
Attaching the updated app
Thanks a Lot Sunny
Exactly what i needed
Hi @sunny_talwar,
I would like to modify the way we calculate aging buckets. Instead of using the current date i.e today() to determine the buckets, I want the calculations to be based on a user-selected date.
For example, if a user selects June 2022 as the filter (format: MMM-YYYY), the 0-30 days bucket should show data from June 1 to June 30, and the 30-60 days bucket should display data from May 2 to May 31.
the 60 - 90 days bucket needs to show data for may 1st to April 2nd.
I have referred the below link and implemented the same but if I select June 2022. it showing data only in 0-30 days bucket for that month.
Superb !!! Neat Solution. You are on fire!!