Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
lweny
Contributor
Contributor

Calculation in Qlik Sense

Hi All, I have a question and wondering whether you can help me out with this. If I have a field named A which has value A1 and A2. Then I'd like to sum the total sales for A2 only. I have created an IF calculation =if([A]='A2', Sum([Total_sales)])) under the Data --> Expression but the result was dash (-). Could you please point out the mistakes I made? Thanks in advance!
1 Solution

Accepted Solutions
miskinmaz
Creator III
Creator III

If you need only Total sales of A2 then you use the set analysis like:
sum({<A={"A2"}>}[Total_sales])

View solution in original post

6 Replies
Anil_Babu_Samineni

Perhaps this?

Sum(TOTAL {<A={'A2'}>} Total_sales)

In your expression, there is small correction needed

=if([A]='A2', Sum([Total_sales)])) // Remove that

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
miskinmaz
Creator III
Creator III

If you need only Total sales of A2 then you use the set analysis like:
sum({<A={"A2"}>}[Total_sales])
lweny
Contributor
Contributor
Author

Hi, thanks for your response. Cool, it works! By the way, I still don't get it and have some questions regarding this, hope you can help me out: 1. About the brackets you use, why should it that much? 2. What the difference between your logic and if it uses TOTAL like @Anil_Babu_Samineni did? Anyway, the result is the same, I'm just wondering about the difference 3. Why can't I use IF like I did before? Thanks before!
lweny
Contributor
Contributor
Author

Hi, thanks for your response. Cool, it works! By the way, I still don't get it and have some questions regarding this as I replied above/below, hope you can help me out. Thanks before!
lweny
Contributor
Contributor
Author

Hi, one more question, if I want to sum the total sales based on 2 conditions, how to add in the another condition? Just use && this sign?
miskinmaz
Creator III
Creator III

You can write the condition within the set analysis using a comma separator. like
sum({<filed1={"cond1"},filed2={"cond2"}>}sales). When you write the expression it is calculated at every row level but if you want to ignore the calculation and get the total of certain dimension you can use the total function. You can search in help.qlik.com.
Please mark the correct solution.