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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
jduluc12
Creator
Creator

Pivot table problem

Hi,

Here is my data set

Aux:

LOAD * INLINE [

    ID, Amount1, Type

    1, 100, A

    1, 130, B

    2, 230, A

    2, 130, A

    2, 140, B

    3, 100, A

    3, 200, A

    3, 300, A

    3, 500, A

    4, 200, A

    4, 300, B

    4, 500, A

   

];

Main:

LOAD * INLINE [

    ID, Amount2

    1, 100

    2, 230

    3, 300

    4, 500

];

I am creating a Pivot table and the purpose of this table is to show

Amount from Amount1 Column if there is Type B associated with the particular ID else take the amount from Main.

Dimension:

ID

Type

Expression:

sum({<ID={2,3,4}>}if(Match(Type,'B'),Amount1,Amount2))

The output looks like this. I do not need the Type column. It is there to just to show where the amount is coming from.

Screen Shot 2017-10-16 at 4.25.08 AM.png

My data should like this

IDAmount
2140
3300
4300

  1. ID 2 should show amount 140 becasue it is associated with Type B in the Table Aux.
  2. ID 3 should show amount 300 becasue there is no Type B's amount in Table Aux so it should take amount 300 from from Table Main's Amount2 column.
  3. ID 4 should show amount 300 becasue it is associated with Type B in the Table Aux.



1 Solution

Accepted Solutions
pradosh_thakur
Master II
Master II

IF(sum({<ID=,Type={'B'}>}(if(Match(Type,'B')>0,Amount1,Amount2)))=0,sum(Amount2),sum({<ID=,Type={'B'}>}(if(Match(Type,'B')>0,Amount1,Amount2))))


if you want only for [id ]2,3,4 please use ID={2,3,4}

regards

Pradosh

Learning never stops.

View solution in original post

17 Replies
sunny_talwar

Try this

If(Sum({<ID = {"=Only(TOTAL <ID> {<Type = {'B'}>} Type) = 'B'"}*{2,3,4}, Type = {'B'}>}Amount1) > 0,

Sum({<ID = {"=Only(TOTAL <ID> {<Type = {'B'}>} Type) = 'B'"}*{2,3,4}, Type = {'B'}>}Amount1),

Sum({<ID = {2,3,4}, Type -= {'B'}>}Amount2))

With ID as dimension

Capture.PNG

Anil_Babu_Samineni

PFA

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
pradosh_thakur
Master II
Master II

Hi

as i thought 1 also qualify and should have value 130 i have added that too. If you don;t you can exclude that.

PFA

regards

Pradosh

Learning never stops.
jduluc12
Creator
Creator
Author

Can You please paste the expression here?

jduluc12
Creator
Creator
Author

Can you please paste the expression here?

Anil_Babu_Samineni

Sunny provide expression as well, I am not changing anything from UI. I just use this?

Aux:

LOAD * INLINE [

    ID, Amount1, Type

    1, 100, A

    1, 130, B

    2, 230, A

    2, 130, A

    2, 140, B

    3, 100, A

    3, 200, A

    3, 300, A

    3, 500, A

    4, 200, A

    4, 300, B

    4, 500, A

] Where Type = 'B';

Main:

LOAD * INLINE [

    ID, Amount2

    1, 100

    2, 230

    3, 300

    4, 500

];

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
jduluc12
Creator
Creator
Author

i can not change the load script. I have to do it in Expression.

sunny_talwar

I gave you an expression? No response to what I gave?

Anil_Babu_Samineni

Then look for Talwar expression? seems working..

If(Sum({<ID = {"=Only(TOTAL <ID> {<Type = {'B'}>} Type) = 'B'"}*{2,3,4}, Type = {'B'}>}Amount1) > 0,

Sum({<ID = {"=Only(TOTAL <ID> {<Type = {'B'}>} Type) = 'B'"}*{2,3,4}, Type = {'B'}>}Amount1),

Sum({<ID = {2,3,4}, Type -= {'B'}>}Amount2))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful