Qlik Community

Ask a Question

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
Live Chat, June 29th 10AM ET. Bring your Qik Sense Enterprise, Client Managed questions! REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
bramvdpoel
Contributor III
Contributor III

If (Field A > Field B ), Then Sum(Calculation

Hello!

Search the forum but could not find any awnsers to my question:

I'm trying to make a #kpi like this:

IF(Field A > Field B, Sum((Field C - Field D) * Field E))

Correction: IF((Field A > Field B, Sum((Field A - Field B)*Field C))

But i can't seem to get to right answer, can anybody help?

1 Solution

Accepted Solutions
tresesco
MVP
MVP

If all three fields are numeric, your expression should work with a sum() outside 'if' in KPI object, i.e.

Sum( If (A > B,  ((A - B) * C))  )

If this is not working in KPI object, check if field C is being treated as text or not and correct that accordingly. Otherwise, try to share a sample app.

View solution in original post

8 Replies
Mauritz_SA
Partner
Partner

Hi there

I'm guessing you have many values in Field A and Field B? If so I think you're going to do an aggregation on those fields to use it in a KPI object. For example IF(Sum(Field A) > Sum(Field B), Sum((Field C - Field D) * Field E)).

Hope this helps.

Regards,

Mauritz

sebastiandperei
Specialist
Specialist

Hi!

If the another answer doesn't works, you could try

sum (if([Field A]>[Field B], ([Field C]-[Field D])*[Field E]))

robert99
Specialist III
Specialist III

Have you tried

sum(IF(Field A > Field B,

(Field C - Field D) * Field E

))

bramvdpoel
Contributor III
Contributor III
Author

This doesn't work, Field A & Field B are numeric field (values range from 0 to 50)

Mauritz_SA
Partner
Partner

Hi @bramvdpoel 

Can you perhaps paste a short extract of your data with the expected output?

Regards,

Mauritz

bramvdpoel
Contributor III
Contributor III
Author

ABC
5310,54
10614,47
2125,64
3212,31
228,64
684,89
231,58
2133,47
1189,17

 

I wrote my formula wrong in my post earlier, here is an example piece.

If (A > B,  ((A minus B) * C)) 

And then i want a total sum of all rows where A is bigger then B in a KPI.

tresesco
MVP
MVP

If all three fields are numeric, your expression should work with a sum() outside 'if' in KPI object, i.e.

Sum( If (A > B,  ((A - B) * C))  )

If this is not working in KPI object, check if field C is being treated as text or not and correct that accordingly. Otherwise, try to share a sample app.

View solution in original post

bramvdpoel
Contributor III
Contributor III
Author

Got the KPI working, thx a lot everbody for the quick respones!