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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
KKumar92
Contributor III
Contributor III

Date & Time Wise Calculation

Hi All,

I am currently working on a report, where my purpose is to show the difference between standard and stock movement quantities.

Two table as follow;

Standard Requirement
DateQty_Required
1/2/202015000
1/3/20208500
1/4/20206500

 

Stock_Movement
DateTimeQty
1/1/20201:008500
1/1/20202:00120
1/1/20204:00365
1/1/202016:00785
1/1/202021:00950
1/1/202023:00350
1/2/20201:00450
1/2/20202:00320
1/2/20204:00450
1/2/202016:00320
1/2/202021:00980
1/2/202023:00750
1/3/20201:001000
1/3/20202:001200
1/3/20204:003200
1/3/202016:00250
1/3/202021:00350
1/3/202023:00400
1/4/20201:00300
1/4/20202:00780
1/4/20204:00650
1/4/202016:00900
1/4/202021:00620
1/4/202023:00700

 

Combining these two tables I want to create an output as follow;

Variance
DateStandard_Qty_RequiredStock_Movement_QtyDifference
1/2/202015000122902710
1/3/2020850019740-11240
1/4/2020650022470-15970

 

As you can see, For a given date "1/2/2020" the Standard_Qty_Required can be taken directly from Standard Requirement Table. However, the Stock_Movement_Qty should be calculated as follow;

Assuming that the system started to capture data from 1/1/2020, to calculate the Stock_Movement_Qty for 1/2/2020, I want to take the sum of quantity of previous day till 6 am of 1/2/2020. Similarly to calculate the Stock_Movement_Qty for 1/3/2020, I want to take the sum of quantity from 1/1/2020 to 6am of 1/3/2020.

Please advise on the above.

Thanks

Labels (1)
5 Replies
Oliver_F
Partner - Creator III
Partner - Creator III

Hi,

if I undertand this correctly Stockmovement from 0 to 6 am should be assigned to the previous day. Can't you do this in the script: If time < 6:00 then Date = Date -1.

With that you would have solved your first problem.

Second problem is that

1/1 = 1 /1

1/2 = 1/1 + 1/2

1/3 = 1/1 + 1/2 + 1/3 (if I got that right)

You should be able to solve that using the above statement in the chart expression.

KKumar92
Contributor III
Contributor III
Author

Hi Oliver,

Here I have made an assumption, where system will record details from 1/1. Therefore, I want to calculate the stock movement as follow;

1/2 = 1/1 (12am to 11.59pm) + 1/2 (12am to 6am)

1/3 = 1/1 (12am to 11.59pm) + 1/2 (12am to 11.59pm) + 1/3 (12am to 6am)

1/4 = 1/1 (12am to 11.59pm) + 1/2 (12am to 11.59pm) + 1/3(12am to 11.59pm) + 1/4 (12am to 6am)

I hope this would give you more clear view on the question I have raised.

Thanks.

Oliver_F
Partner - Creator III
Partner - Creator III

Hi,

I still think that my above solution will do that (only edge case is 1/1).

But maybe you prefer a little more straight forward approach:

1) Create a Key from Date & Time (e.g. Date &'-'& Time as Key)

2) Create a new Table with Date2.

3) Now you need to built a logic that assigns each Date2 all the right Keys from your original Table. 

But I think this will only be a good idea if your data has not to many rows, because this will expand your data a bit.

Saravanan_Desingh
MVP
MVP

Try this. Also Please check your SUM.

tab1:
LOAD *, If(Time>='0:00' And Time<'12:00','Y') As K1,
	If(Time>='0:00' And Time<='6:00','Y') As K2;
LOAD RecNo() As ID,* INLINE [
    Date, Time, Qty
    1/1/2020, 1:00, 8500
    1/1/2020, 2:00, 120
    1/1/2020, 4:00, 365
    1/1/2020, 16:00, 785
    1/1/2020, 21:00, 950
    1/1/2020, 23:00, 350
    1/2/2020, 1:00, 450
    1/2/2020, 2:00, 320
    1/2/2020, 4:00, 450
    1/2/2020, 16:00, 320
    1/2/2020, 21:00, 980
    1/2/2020, 23:00, 750
    1/3/2020, 1:00, 1000
    1/3/2020, 2:00, 1200
    1/3/2020, 4:00, 3200
    1/3/2020, 16:00, 250
    1/3/2020, 21:00, 350
    1/3/2020, 23:00, 400
    1/4/2020, 1:00, 300
    1/4/2020, 2:00, 780
    1/4/2020, 4:00, 650
    1/4/2020, 16:00, 900
    1/4/2020, 21:00, 620
    1/4/2020, 23:00, 700
];

MinDt:
LOAD Min(Date) as MinDate
Resident tab1;

LET vMinDate = Peek('MinDate');

AsOfTable:
LOAD DISTINCT Date as AsOfDate, 
	Date - IterNo() + 1 as Date
Resident tab1
While Date - IterNo() + 1 >= $(vMinDate)
;

Drop Table MinDt;
Saravanan_Desingh
MVP
MVP

Output:

commQV08.PNG