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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need help in Expression(Script)

Hi,

Need help in Orange colored part, how to do this sql part.

CurrentData:

 

SQL

SELECT

    CURDATE() as Date1,

    Customer_id,

    Customer_Sub,

    Customer_Location,

    Invoice_No,

    Invoice_Amount,

  

     If(GETDATE() - [DueDate] >= 30,Count(Invoice_No) as NbOverdueInv,

        If(GETDATE() - [DueDate] >= 30,Sum(Invoice_Amount) as NbOverdueInv,


    Count(Invoice_No) as NumberofInvoices,

    Sum(Invoice_Amount) as TotalAmt

FROM Master.dbo Group by Customer_id,Customer_Sub,Customer_Location, Invoice_No,Invoice_Amount;

STORE CurrentData into CurrentData.qvd(qvd);

Regards,

Chriss

4 Replies
kumarnatarajan
Partner - Specialist
Partner - Specialist

Hi,

Close your if condition brackets. and Field name must be unique.

Else

use below mentioned code.

Ex:

if(DATEDIFF(day,Now(),[DueDate])>= 30,Count(Invoice_No)) as NbOverdueInvCount,

if(DATEDIFF(day,Now(),[DueDate])>= 30,Sum(Invoice_Amount)) as NbOverdueInvSum,

Not applicable
Author

TEST:

Load *,

If(GETDATE() - [DueDate] >= 30,Count(Invoice_No) as NbOverdueInv,

        If(GETDATE() - [DueDate] >= 30,Sum(Invoice_Amount) as NbOverdueInv;

SQL

SELECT *


FROM Master.dbo

CurrentData:

load

Customer_id,

Customer_Sub,

Customer_Location,

Invoice_No,

Invoice_Amount,

NbOverdueInv,

NbOverdueInv,

Count(Invoice_No) as NumberofInvoices,

    Sum(Invoice_Amount) as TotalAmt

FROM TEST Group by Customer_id,Customer_Sub,Customer_Location, Invoice_No,Invoice_Amount,NbOverdueInv,NbOverdueInv;


STORE CurrentData into CurrentData.qvd(qvd);


Not applicable
Author

Hi Kumar,

Thanks for your reply, as I am getting the error of "Incorrect syntax near the keyword 'if'."

In the SQL select is not possible to use the IF conditon.

Regards

Chriss

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

CASE WHEN GETDATE() - [DueDate] >= 30 THEN Count(Invoice_No) END as NbOverdueInv,

CASE WHEN GETDATE() - [DueDate] >= 30 THEN Sum(Invoice_Amount) END as NbOverdueInv,


talk is cheap, supply exceeds demand