Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
kdavorin
Contributor II
Contributor II

QlikView difference between columns

Hello.

I am newbie to QlikView and would greatly appreciate any help. Because of my very busy schedule I am unable to dive deeper into the QlikView topics at the moment, so any suggestion would be of great value!

I have the following data structure:

ScenarioKPIValue
AK110
AK220
AK330
BK15
BK213
BK327

 

How could I achieve the following report?

KPIABDifference (A-B)
K11055
K220137
K330273

 

Thank you very much for your time and effort.

Labels (1)
1 Solution

Accepted Solutions
Taoufiq_Zarra

@kdavorin  if you need a sample solution in chart for 2 (A and B)

in dimension: KPI

measures1(A): =Only({<Scenario={'A'}>}Value)

measures B(B): =Only({<Scenario={'B'}>}Value)

measure(A-B): =Only({<Scenario={'A'}>}Value)-Only({<Scenario={'B'}>}Value)

output:

Taoufiq_Zarra_0-1629362960281.png

or other solution more global in Script using generic load :

Tmp:
 load KPI,Scenario,  Value INLINE [
    Scenario, KPI, Value
    A, K1, 10
    A, K2, 20
    A, K3, 30
    B, K1, 5
    B, K2, 13
    B, K3, 27
];

DATA:
 Generic LOAD * Resident Tmp;
 
CombinedGenericTable:

Load distinct KPI resident Tmp;

Drop Table   Tmp; 

FOR i = NoOfTables()-1 to 0 STEP -1

  LET vTable=TableName($(i));
  IF WildMatch('$(vTable)', 'DATA.*') THEN 

  LEFT JOIN ([CombinedGenericTable]) LOAD distinct * RESIDENT [$(vTable)];

  DROP TABLE [$(vTable)];

  ENDIF 

NEXT i

In chart: dimension KPI, A and B

measure A-B

 

output:

Taoufiq_Zarra_1-1629363049976.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

8 Replies
Taoufiq_Zarra

@kdavorin  if you need a sample solution in chart for 2 (A and B)

in dimension: KPI

measures1(A): =Only({<Scenario={'A'}>}Value)

measures B(B): =Only({<Scenario={'B'}>}Value)

measure(A-B): =Only({<Scenario={'A'}>}Value)-Only({<Scenario={'B'}>}Value)

output:

Taoufiq_Zarra_0-1629362960281.png

or other solution more global in Script using generic load :

Tmp:
 load KPI,Scenario,  Value INLINE [
    Scenario, KPI, Value
    A, K1, 10
    A, K2, 20
    A, K3, 30
    B, K1, 5
    B, K2, 13
    B, K3, 27
];

DATA:
 Generic LOAD * Resident Tmp;
 
CombinedGenericTable:

Load distinct KPI resident Tmp;

Drop Table   Tmp; 

FOR i = NoOfTables()-1 to 0 STEP -1

  LET vTable=TableName($(i));
  IF WildMatch('$(vTable)', 'DATA.*') THEN 

  LEFT JOIN ([CombinedGenericTable]) LOAD distinct * RESIDENT [$(vTable)];

  DROP TABLE [$(vTable)];

  ENDIF 

NEXT i

In chart: dimension KPI, A and B

measure A-B

 

output:

Taoufiq_Zarra_1-1629363049976.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
kdavorin
Contributor II
Contributor II
Author

@Taoufiq_Zarra Thank you very much! That simple solution works perfect! 🙂

How do I achieve the same output, if my data structure is the following.

ScenarioKPISubKPI1SubKPI2Value
AK1-S2a3
AK1-S2b7
AK2-S2a11
AK2-S2b9
AK3S1aS2c4
AK3S1aS2d7
AK3S1bS2c10
AK3S1bS2d9
BK1-S2a2
BK1-S2b3
BK2-S2a6
BK2-S2b7
BK3S1aS2c2
BK3S1aS2d8
BK3S1bS2c11
BK3S1bS2d6

 

Thank you once again!

Taoufiq_Zarra

@kdavorin  and the what is the expected output ?

the first or the second solution ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
kdavorin
Contributor II
Contributor II
Author

@Taoufiq_Zarra The expected output is the from the simple (first) solution. 

Taoufiq_Zarra

@kdavorin  what is the expected output from this input :

ScenarioKPISubKPI1SubKPI2Value
AK1-S2a3
AK1-S2b7
AK2-S2a11
AK2-S2b9
AK3S1aS2c4
AK3S1aS2d7
AK3S1bS2c10
AK3S1bS2d9
BK1-S2a2
BK1-S2b3
BK2-S2a6
BK2-S2b7
BK3S1aS2c2
BK3S1aS2d8
BK3S1bS2c11
BK3S1bS2d6
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
kdavorin
Contributor II
Contributor II
Author

@Taoufiq_Zarra The expected output is the same.

KPIABDifference (A-B)
K11055
K220137
K330273

 

It's just that the input data structure now contains some sub KPI's.

Taoufiq_Zarra

@kdavorin  just change Only to sum

in dimension KPI

measures1(A): =sum({<Scenario={'A'}>}Value)

measures B(B): =sum({<Scenario={'B'}>}Value)

measure(A-B): =sum({<Scenario={'A'}>}Value)-sum({<Scenario={'B'}>}Value)

output:

Taoufiq_Zarra_0-1629366042298.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
kdavorin
Contributor II
Contributor II
Author

@Taoufiq_Zarra Thank you! Works like a charm! 😀