Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How can i perform operation on the field which is created by "as" clause ?

Hello Community ,

I need your help i want that How can i perform operation on the field which is created by "as" clause ?

The query is given below :

LOAD

    Slug,

    Block,

    hour(time#("Time",'hh:mm:ss:ff')) as [Extracted Hours],

    if([Extracted Hours]=0,Count([Extracted Hours])) as [00:00 - 01:00],

    if([Extracted Hours]=1,Count([Extracted Hours])) as [01:00 - 02:00],

    Count(Slug) as "Story Repeat"

FROM

Source File

Group By Slug,Block,"Extracted Hours";

In this query i created a new field named as "Extracted Hours" and i want to use the value of this field but i am getting error that "Extracted Hour" field not exist.

Kindly suggest me how could i use ?

Thanks in Advance.

Regards

1 Solution

Accepted Solutions
sravan_v007
Partner - Contributor III
Partner - Contributor III

Hi,

There are 2 ways..

1. You have to take complete value what you mentioned before "as".

i.e. from above script

LOAD

    Slug,

    Block,

    hour(time#("Time",'hh:mm:ss:ff')) as [Extracted Hours],

    if(hour(time#("Time",'hh:mm:ss:ff'))=0,Count(hour(time#("Time",'hh:mm:ss:ff')))) as [00:00 - 01:00],

    if(hour(time#("Time",'hh:mm:ss:ff'))=1,Count(hour(time#("Time",'hh:mm:ss:ff')))) as [01:00 - 02:00],

    Count(Slug) as "Story Repeat"

FROM

Source File

Group By Slug,Block,Time;

2. Take a resident of the table and perform the calculations.

T1:

LOAD

    Slug,

    Block,

    hour(time#("Time",'hh:mm:ss:ff')) as [Extracted Hours],

Slug

FROM

Source File

T2:

LOAD

    Slug,

    Block,

    [Extracted Hours],

    if([Extracted Hours]=0,Count([Extracted Hours])) as [00:00 - 01:00],

    if([Extracted Hours]=1,Count([Extracted Hours])) as [01:00 - 02:00],

    Count(Slug) as "Story Repeat"

FROM

Source File

Group By Slug,Block,"Extracted Hours";

Regards,

Sravan.

View solution in original post

3 Replies
sravan_v007
Partner - Contributor III
Partner - Contributor III

Hi,

There are 2 ways..

1. You have to take complete value what you mentioned before "as".

i.e. from above script

LOAD

    Slug,

    Block,

    hour(time#("Time",'hh:mm:ss:ff')) as [Extracted Hours],

    if(hour(time#("Time",'hh:mm:ss:ff'))=0,Count(hour(time#("Time",'hh:mm:ss:ff')))) as [00:00 - 01:00],

    if(hour(time#("Time",'hh:mm:ss:ff'))=1,Count(hour(time#("Time",'hh:mm:ss:ff')))) as [01:00 - 02:00],

    Count(Slug) as "Story Repeat"

FROM

Source File

Group By Slug,Block,Time;

2. Take a resident of the table and perform the calculations.

T1:

LOAD

    Slug,

    Block,

    hour(time#("Time",'hh:mm:ss:ff')) as [Extracted Hours],

Slug

FROM

Source File

T2:

LOAD

    Slug,

    Block,

    [Extracted Hours],

    if([Extracted Hours]=0,Count([Extracted Hours])) as [00:00 - 01:00],

    if([Extracted Hours]=1,Count([Extracted Hours])) as [01:00 - 02:00],

    Count(Slug) as "Story Repeat"

FROM

Source File

Group By Slug,Block,"Extracted Hours";

Regards,

Sravan.

Not applicable
Author

Hey Saravan its's working percfectly thanks a lot for the help ..

Regards

Not applicable
Author

This can also be done using a preceeding load.

LOAD

  *

    ,if([Extracted Hours]=0,Count([Extracted Hours])) as [00:00 - 01:00]

    ,if([Extracted Hours]=1,Count([Extracted Hours])) as [01:00 - 02:00]

;

LOAD

    Slug,

    Block,

    hour(time#("Time",'hh:mm:ss:ff')) as [Extracted Hours],

    Count(Slug) as "Story Repeat"

FROM

Source File

Group By Slug,Block,"Extracted Hours";