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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
adamdavi3s
Master
Master

Island dimension in a table, expression avoiding an IF?!

Hi All,


Bit of a strange one this. We have an island dimension, which has the same values as some column names in the fact table.

The simple reason being the dataset is 65,000,000 rows and having this dimension as an additional column would potentially increase this by 20 times!!

Therefore under the advice of qliktech we created the island dimension, and renamed the amount columns with the same values.

Consider this as a basic example:

Island Table:

cost_type
BLOOD
DRUGS
WARDS AND NURSING
IMPLANTS

Fact Table:

Header 1Header 2Header 3Header 4Header 5
HRGBLOODDRUGSWARDS AND NURSINGIMPLANTS
a100204023
b2001050456

On the whole this works very well for us, the only issue being when we want to create a table with this dimension, the only way we've found to add the expression is a large IF statement, for example:

=

if(cost_type='BLOOD',sum(BLOOD),

if(cost_type='DRUGS',sum(DRUGS),

if(cost_type='WARDS AND NURSING',sum([WARDS AND NURSING]),

IF(cost_type='IMPLANTS',SUM(IMPLANTS),0))))

But this is obviously an incredibly slow way for the system to calculate

Is there a simple way to include the dimension in the formula?

I was hoping something like this would work:

=sum('['&cost_type&']')

But it doesn't

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You can try a pick-match combination:

=pick(match(cost_type,'BLOOD','DRUGS','WARDS AND NURSING','IMPLANTS'),

sum(BLOOD),

sum(DRUGS),

sum([WARDS AND NURSING]),

sum(IMPLANTS))

But the smart way is to use the CrossTable function in the script:

LOAD @1 as cost_type

FROM

comm89620.xls

(biff, no labels, table is cost_types$);

CrossTable(cost_type, value)

LOAD HRG,

     BLOOD,

     DRUGS,

     [WARDS AND NURSING],

     IMPLANTS

FROM

comm89620.xls

(biff, embedded labels, table is fact$);

You can then use cost_type as dimension and sum(value) as expression. See attached qvw


talk is cheap, supply exceeds demand

View solution in original post

3 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You can try a pick-match combination:

=pick(match(cost_type,'BLOOD','DRUGS','WARDS AND NURSING','IMPLANTS'),

sum(BLOOD),

sum(DRUGS),

sum([WARDS AND NURSING]),

sum(IMPLANTS))

But the smart way is to use the CrossTable function in the script:

LOAD @1 as cost_type

FROM

comm89620.xls

(biff, no labels, table is cost_types$);

CrossTable(cost_type, value)

LOAD HRG,

     BLOOD,

     DRUGS,

     [WARDS AND NURSING],

     IMPLANTS

FROM

comm89620.xls

(biff, embedded labels, table is fact$);

You can then use cost_type as dimension and sum(value) as expression. See attached qvw


talk is cheap, supply exceeds demand
adamdavi3s
Master
Master
Author

Sorry I didn't get my usual email to tell me this reply was here!

I'll try the pick match and see if it runs better than the IF statement.

The cross-table unfortunately isn't viable due to the volumes of data!

adamdavi3s
Master
Master
Author

Pick match improved the speed 4 fold

10 seconds down to 2.5 on my larger data set.