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

Set Analysis. Sum with help other field.

Hello.

Help to solve my problem. There are 3 tables:

1) Facts

ItemsLocationsQty
Item1Location11
Item1Location21
Item1Location31
Item1Location41
Item2Location21
Item2Location31
Item2Location41
Item3Location11
Item3Location21
Item3Location31

2) LinkItemsAndDim

ItemsDimensions
Item1Dim1
Item2Dim1
Item3Dim2

3) DimensionsSetup

DimensionsLocationsSetup
Dim1Location1
Dim1Location2
Dim2Location3

Need to sum column Qty only those records where the field Locations match with field LocationsSetup.

DimensionsGroupQtySum
Dim13
Dim21

Without Set Analysis formula is as follows:

sum (if (Locations = LocationsSetup, Qty))

But it is uneffective for large data (> 10 million rows).

Help, please, write a formula using the Set Analysis.

1 Solution

Accepted Solutions
pokassov
Specialist
Specialist

Hello!

I don't think that set analysis can help in this case. I mean 10 million rows...

Can you change your script?

DimensionsSetup:

LOAD Dimensions,

     LocationsSetup

FROM

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

LinkItemsAndDim:

LOAD Items,

     Dimensions

FROM

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

t1:

NoConcatenate LOAD

*

Resident

  DimensionsSetup;

Left Join (t1)

LOAD

  *

Resident

  LinkItemsAndDim;

MapTable:

Mapping LOAD

  Items,

  LocationsSetup

Resident

  t1;

DROP Table

  t1;

Fact:

LOAD Items,

     Locations,

     Qty,

     if(ApplyMap('MapTable',Items,-1)=Locations,1,0) as _Flag

FROM

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

View solution in original post

5 Replies
Anonymous
Not applicable
Author

You can load a mapping table

with columns Location,Flag    /// use location setup data to load this field

                        Location1,'1'

.....

now you can use apply map and add flag column to your Fact table. so now your main table have 1 for loactions which are present in DimensionsSetup table

=sum({<Flag='1'>}Qty)

Thanks

BKC

ramoncova06
Partner - Specialist III
Partner - Specialist III

try with a possible selections in your set analysis

sum({<Locations =P(LocationsSetup)>} Qty)

pokassov
Specialist
Specialist

Hello!

I don't think that set analysis can help in this case. I mean 10 million rows...

Can you change your script?

DimensionsSetup:

LOAD Dimensions,

     LocationsSetup

FROM

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

LinkItemsAndDim:

LOAD Items,

     Dimensions

FROM

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

t1:

NoConcatenate LOAD

*

Resident

  DimensionsSetup;

Left Join (t1)

LOAD

  *

Resident

  LinkItemsAndDim;

MapTable:

Mapping LOAD

  Items,

  LocationsSetup

Resident

  t1;

DROP Table

  t1;

Fact:

LOAD Items,

     Locations,

     Qty,

     if(ApplyMap('MapTable',Items,-1)=Locations,1,0) as _Flag

FROM

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

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Use mapping to bring the dimensions into the table, and set a flag for the matches:

MapDims:

Mapping LOAD Items,

    Dimensions

FROM [testRangeExt.xls]

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

MapLocs:

Mapping LOAD LocationsSetup,

    Dimensions 

FROM [testRangeExt.xls]

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

Data:

LOAD *,

    If(ItemDim = LocationDim, 1, 0) As DimMatch

;

LOAD Items,

    Locations, 

    ApplyMap('MapDims', Items) As ItemDim,

    ApplyMap('MapLocs', Locations) As LocationDim,

    Qty

FROM [testRangeExt.xls]

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


Now use either ItemDim or LocationDim as a table dimension, and use the Matchflag in the expression:

    =Sum({<DimMatch = {1}>} Qty)

This should perform well on a large data set.

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thanks!

Using ApplyMap and Mapping load helped to solve this problem.