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: 
profilejamesbond
Creator II
Creator II

% calculation after data source change

Hi,

I have "data source a" from 01.01.2025 to 28.06.2025 and "data source b" from 29.06.2025 to today()-1.

I have % Expression to calculate KPI:

 

num(

Sum({<Source = {'A'}>} Column A) / (Sum({<Source = {'A'}>} Column B) - Sum({<Source = {'A'}>} Column C))

+

Sum({<Source = {'B'}>} Column A) / (Sum({<Source = {'B'}>} Column B) - Sum({<Source = {'B'}>} Column D))

,'#0,0 %')

 

Source = {'A'} used Column C while Source = {'B'} used Column D to calculate the %.

 

Now, the problem is Source = {'A'} returns me 60% while Source = {'B'} returns me 70% and sum up is 130% which is not correct. While both expressions are correct and returns me the result based on number for Column A, B, C, and D.

 

How to fix this logical issue ?

 

Thanks

 

Labels (2)
1 Solution

Accepted Solutions
Or
MVP
MVP

Your If() should be inside the Sum(), but it seems to be summing Column C either way so I'm not sure it matters? Or is that a typo?

Sum(If (Data Source = A, Column C,Column D))

Or

Sum(Pick(Match(Data Source,A,B),Column C, Column D))

View solution in original post

5 Replies
Or
MVP
MVP

No idea what exactly you're trying to achieve, but why are you summing the values in the first place? Shouldn't you be averaging them or subtracting them? This expression is confusing... 

profilejamesbond
Creator II
Creator II
Author

Hi,

I am summing up due to the 2 reason:

1. Both expressions are different due to availability of the data. For example: Source A has Column C while Source B has Column D in the calculation

 

2. Before 29.06.2025 was data labeled with Source A and after that Source B. So, the idea is to show the values when user Select 01.01.2025 with the Source A Expression and if the user Select After 29.06.2025 then it must see the calculation based on Expression 2. And if there is no selection then calculated based on Expression.

 

Thanks

Or
MVP
MVP

I'm afraid I'm still struggling to follow the logic / formula / explanation. 

{A} returns 60%, {B} returns 70%, you say both values are correct, yet 130% is not correct despite the fact that you are performing a simple addition between A and B?

 

profilejamesbond
Creator II
Creator II
Author

Let me make it more simple,
I have two fields which needs to be switch in the Expression:

I want to change the column or swap the column for Data Source ?

Current Expression:

Sum(Column A) / (Sum(Column B) - Sum(Column C))

 

New Expression:
Sum(Column A) / (Sum(Column B) - If (Data Source = A, Sum(Column C), If(Data Source = B, Sum(Column C))))

 

Somehow, new expression is not working or may be there is a logical error.

Or
MVP
MVP

Your If() should be inside the Sum(), but it seems to be summing Column C either way so I'm not sure it matters? Or is that a typo?

Sum(If (Data Source = A, Column C,Column D))

Or

Sum(Pick(Match(Data Source,A,B),Column C, Column D))