Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

thewillemzelluf
New Contributor II

switch case?

Hy everybody,

I have a problem with the sales date.


I try to match the sales to the date they enter the system. However, it is not always filled and in that case I want to take the invoice date. This one is also not always filled and in the latter case I want to take order date. My question: How can i do that (in this order)?

Now I have read something about switch case but not enough to apply it. can anyone help me with explenation or an example?


Thank you in advance!!


Tags (2)
1 Solution

Accepted Solutions
sasiparupudi1
Honored Contributor III

Re: switch case?

My be try

Map_Order_date:

Load

Your ID,

Order Date

From Your Table

;

Sales Table

Load

Applymap('Map_Order_date',your ID,Null()) as OrderDate

If(Len(trim(SalesDate))>0,SalesDate,

    If( (Len(Trim(InvoiceDate))>0 and InvoiceDate<>makedate(2017,1,1)),InvoiceDate,

Applymap('Map_Order_date',your ID,Null())

))  As NewDate

7 Replies
MVP
MVP

Re: switch case?

Have a look at the Alt() function

https://help.qlik.com/en-US/sense/April2018/Subsystems/Hub/Content/Scripting/ConditionalFunctions/al...

, maybe something like

LOAD

     Date( Alt( SalesDate, InvoiceDate, OrderDate)) as NewDate,

     ...

FROM Facts;

Take care to handle your date fields appropriately:

Get the Dates Right

Why don’t my dates work?

thewillemzelluf
New Contributor II

Re: switch case?

Thankyou Stefan,

But it seems that I will get another problem. Invoice Date is sometimes (by default) filled with 01-01-2017 and I think that is not recognized by if (alt). if (alt) will choose the 01-01-2017 date I think. And what I want is that I can also filter this

MVP
MVP

Re: switch case?

Willem, I am not sure how you want to handle the Invoice Date's default value. Do you want to replace it when loading?

Or just handle it within the Alt() function?

LOAD

     Date( Alt( SalesDate, If( InvoiceDate = Makedate(2017),Null(), InvoiceDate), OrderDate)) as NewDate,

     ...

FROM Facts;

thewillemzelluf
New Contributor II

Re: switch case?

Stefan,


It almost worked out but there's still one problem. the 'OrderDate' field is in another table. Do you also have a solution for that?

ps: Thanks in advance for your help!

sasiparupudi1
Honored Contributor III

Re: switch case?

My be try

Map_Order_date:

Load

Your ID,

Order Date

From Your Table

;

Sales Table

Load

Applymap('Map_Order_date',your ID,Null()) as OrderDate

If(Len(trim(SalesDate))>0,SalesDate,

    If( (Len(Trim(InvoiceDate))>0 and InvoiceDate<>makedate(2017,1,1)),InvoiceDate,

Applymap('Map_Order_date',your ID,Null())

))  As NewDate

thewillemzelluf
New Contributor II

Re: switch case?

Thanks Sasidhar!

It worked out!

sasiparupudi1
Honored Contributor III

Re: switch case?

Great, Please close this thread by marking a correct answer and any helpful answers

Community Browser