Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Assume blank value as today

I have a field called SessionDate, which is sometimes blank. When it's blank i want to assume today's date.

How would i do this in my data load?

7 Replies
maxgro
MVP
MVP

if(len(trim(SessionDate))=0, num(today()), SessionDate) as SessionDate

Not applicable
Author

Sorry, slight change to the field name. It is the SessionClosedDate field which is sometimes blank

How would I incorporate that in my load script

My load script is as follows

UserSessionDetails:

LOAD UserName,

    SessionId,

    Environment,

    Replace(DisconnectionReason, 'ClientConnectionClosed. Reason:','') As DisconnectionReason,

    Date(DayStart(Date(SessionStarted,'DD/MM/YYYY')),'YYYY-MM-DD') As SessionStartedDate,

  MakeTime(Hour(SessionStarted), Minute(SessionStarted), Second(SessionStarted))  As SessionStartedTime,

  Hour(SessionStarted) As SessionStartedHour,

    SessionStarted,

    Date(DayStart(Date(SessionClosed,'DD/MM/YYYY')),'YYYY-MM-DD') As SessionClosedDate,

  MakeTime(Hour(SessionClosed), Minute(SessionClosed), Second(SessionClosed))  As SessionClosedTime,

  Hour(SessionClosed) As SessionClosedHour,

    SessionClosed,

    FlashPlayer,

    Firm,

    IPAddress,

    TestAccount,

    Disconnection,

    Reconnection,

    GeneralOutage,

    FirmOutage,

    WorkingDayDisconnect,

    WorkingDayReconnect;

SQL SELECT *

FROM dbo.usersessiondetails;

UserSessionDetails_x_Dates:

Load SessionId,

          Date( SessionStartedDate + IterNo() - 1 ) as SessionDate

          Resident UserSessionDetails

          While IterNo() <= SessionClosedDate - SessionStartedDate + 1 ;

maxgro
MVP
MVP

maybe you can replace your last statement with

Tmp:

Load SessionId,

          Date( SessionStartedDate + IterNo() - 1 ) as SessionDate

          Resident UserSessionDetails

          While IterNo() <= SessionClosedDate - SessionStartedDate + 1 ;

                   

UserSessionDetails_x_Dates:

NoConcatenate

  load

  SessionId,

  if(len(trim(SessionDate))=0, num(today()), SessionDate) as SessionDate

Resident

  Tmp;

drop Table Tmp;          

Not applicable
Author

Hi Massimo,

it was my fault in the first post. It is actually the SessionClosedDate field which is sometimes blank, however when i substitute this in your script is doesn't work

UserSessionDetails:

LOAD UserName,

    SessionId,

    Environment,

    Replace(DisconnectionReason, 'ClientConnectionClosed. Reason:','') As DisconnectionReason,

    Date(DayStart(Date(SessionStarted,'DD/MM/YYYY')),'YYYY-MM-DD') As SessionStartedDate,

  MakeTime(Hour(SessionStarted), Minute(SessionStarted), Second(SessionStarted))  As SessionStartedTime,

  Hour(SessionStarted) As SessionStartedHour,

    SessionStarted,

    Date(DayStart(Date(SessionClosed,'DD/MM/YYYY')),'YYYY-MM-DD') As SessionClosedDate,

  MakeTime(Hour(SessionClosed), Minute(SessionClosed), Second(SessionClosed))  As SessionClosedTime,

  Hour(SessionClosed) As SessionClosedHour,

    SessionClosed,

    FlashPlayer,

    Firm,

    IPAddress,

    TestAccount,

    Disconnection,

    Reconnection,

    GeneralOutage,

    FirmOutage,

    WorkingDayDisconnect,

    WorkingDayReconnect;

SQL SELECT *

FROM dbo.usersessiondetails;

Tmp:

Load SessionId,

          Date( SessionStartedDate + IterNo() - 1 ) as SessionDate

          Resident UserSessionDetails

          While IterNo() <= SessionClosedDate - SessionStartedDate + 1 ;

UserSessionDetails_x_Dates:

NoConcatenate

  load

  SessionId,

  if(len(trim(SessionClosedDate))=0, num(today()), SessionClosedDate) as SessionClosedDate

Resident

  Tmp;

drop Table Tmp;

PrashantSangle

Hi

Replace this with your SessionStartedDate Field.

if(isnull(SessionStarted),

Date(DayStart(Date(Today(),'DD/MM/YYYY')),'YYYY-MM-DD'),

Date(DayStart(Date(SessionStarted,'DD/MM/YYYY')),'YYYY-MM-DD')

) As SessionStartedDate



Regards,

PS

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
PrashantSangle

Hi,

Try this

if(isnull(SessionClosed),

Date(DayStart(Date(Today(),'DD/MM/YYYY')),'YYYY-MM-DD'),

Date(DayStart(Date(SessionClosed,'DD/MM/YYYY')),'YYYY-MM-DD')

) As SessionClosedDate


Regards,

PS


Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
maxgro
MVP
MVP

could you post your qlik doc?