Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Script Problem

Hi friends

i have table fields like below:

Customer:

load TRANSACTIONDATE,

        QTY

FROM CUSTOMER;

Here TRANACTIONDATE will be 02-JAN-12 05:15:50 etc.In Qty field,  i have to split as OpeningStockQty and ClosingStockQty.

The following date 02-JAN-12 00:00:00  Quantity as opening StockQty and 02-JAN-12 22:01:12 as ClosingStockQty.

how can i achieve this?

Please help me out .

Thanks in Advance

Suresh

7 Replies
Not applicable
Author

This is for calculating opening And Closing Stock Qty On the Same date

minimum timestamp  qty will be opening stock ,Maximum timestamp quantity will be Closing Stock qty on the Same date

erichshiino
Partner - Master
Partner - Master

Hi,  Suresh.

You may read your resident table twice and create a flag ( or two separed dimensions)

The script would be more or less like this :

// --------------------------------------------

Customer:

load TRANSACTIONDATE,

daystart( TRANSACTIONDATE) as DATE,

        QTY

FROM CUSTOMER;

Fact:

Load DATE, min ( TRANSACTIONDATE)  as Timestamp, 

QTY  as OpeningStock

Resident CUSTOMER

group by DATE;

Concatenate (Fact)

Load DATE, max( TRANSACTIONDATE)  as Timestamp, 

QTY  as Closing

Resident CUSTOMER

group by DATE;

// --------------------------------------------

OR

// --------------------------------------------

Customer:

load TRANSACTIONDATE,

daystart( TRANSACTIONDATE) as DATE,

        QTY

FROM CUSTOMER;

Fact:

Load DATE, min ( TRANSACTIONDATE)  as Timestamp, 

QTY  as Stock,

'Opening' as Movement

Resident CUSTOMER

group by DATE;

Concatenate (Fact)

Load DATE, max( TRANSACTIONDATE)  as Timestamp, 

QTY  as Stock,

'Closing' as Movement

Resident CUSTOMER

group by DATE;

// --------------------------------------------

Hope this helps,

Erich

Not applicable
Author

Hi Erich

Min(tranasction_date) is not working here

it says ODBC read failed.

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Can you post your code here?

Celambarasan

Not applicable
Author

hi Celambarasan

here is my Code

Inventory:
LOAD  TRANSACTION_ID,
      TRANSACTION_QUANTITY,
      Timestamp#(TRANSACTION_DATE) as MaxTransactionNumber,
      TRANSACTION_DATE,
      daystart(TRANSACTION_DATE) as DATE from Customer;

Fact:
load DATE,
     min(TRANSACTION_DATE) as TimeStamp,
     TRANSACTION_QUANTITY as OpeningStockQty
     Resident Inventory Group by DATE;
    
    
Concatenate(Fact)  
Load DATE,max(TRANSACTION_DATE) as TimeStamp,
     TRANSACTION_QUANTITY as ClosingStockQty
     Resident Inventory Group by DATE;

it shows fact table not found


         

Not applicable
Author

Hi friends

can anyone help me out of this problem?

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Try with this

     Inititally your loading from table you have to use Select instead of load.here Other than inventory table uses the already loaded data so it needs load.

Inventory:
SELECT TRANSACTION_ID,
      TRANSACTION_QUANTITY,
      Timestamp#(TRANSACTION_DATE) as MaxTransactionNumber,
      TRANSACTION_DATE,
      daystart(TRANSACTION_DATE) as DATE FROM Customer;

Fact:
load DATE,
     min(TRANSACTION_DATE) as TimeStamp,
     TRANSACTION_QUANTITY as OpeningStockQty
     Resident Inventory Group by DATE;
    
    
Concatenate(Fact)  
Load DATE,max(TRANSACTION_DATE) as TimeStamp,
     TRANSACTION_QUANTITY as ClosingStockQty
     Resident Inventory Group by DATE;