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: 
Not applicable

Set Analysis: Sum with multiple conditions

Hi best QV Community,

I’ve been using QlikView now for few months very smoothly without any major problem until now.

I’ve been spending a lot of time recently searching for an equivalent to (Excel) SUMIFS in QlikView using the values of a dimension as input conditions. I thought this was a straight forward task but my limited knowledge proved that I was wrong.

To illustrate the problem with a simple example:

Let’s say that we have a data set containing the following fields [Date], [Employee], [Expenditures] and [Balance] (see attached picture).  Using those fields I need to calculate the daily income for each active employee. This is a straight forward task in Excel using SUMIFS or SUMPRODUCT (See the solution in Excel in the attached picture).

So in short I need to find a way to translate: D10-SUMIFS(D:D,A:A,A10-1,B:B,B10)+C10

To something like that in QlikView:  Balance - Sum ( { <Date =Date-1, Employee= Employee> } Balance) + Expenditures

I order to create a new dimension called [Income]. I also tried to use a different kind of Sum(if(conditions)...., Balance) without any success.

I belive that there must be a way to achieve that in QlikView but my knowledge in that matter seems to be limited. I therefore deeply appreciate any help from the community.

Many thanks

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Please check ....

View solution in original post

21 Replies
MK_QSL
MVP
MVP

Can you provide some sample data or apps?

This can be done by using previous and peek function in script.

Not applicable
Author

Hi, you  can created 2 variables:

vDate= date-1

vEmployee= employee

so your expression changes to this way

Balance - Sum({Date={'$(vDate)'}, Employee={'$(vEmployee)'}} Balance) + Expenditures

if this does not help you, please attach an qvw example

regards,

Luis

santharubban
Creator III
Creator III

try this

(balance) - (RangeSum(Above(Sum(balance),Date-1,Employee))+sum(Expenditures))

else upload the sample application

Not applicable
Author

Hi Manish,

Thanks for you reply. Well the actual data set is huge. But I created a similar invirement to simplify. Please see the attached Excel Data set. You can just load Date, Employee, Expenditures and Balance and help me to calculate the Income as it is mentioned in the Excel solution.

Many thanks!

ashwanin
Specialist
Specialist

Your Income is the sum of Balance + Expenditure. Put below in the expression for the output.

Sum({Date={'$(vDate)'}, Employee={'$(vEmployee)'}} Balance) + Expenditures

MK_QSL
MVP
MVP

Please check enclosed file and let me know if anything wrong.

UPDATE.... please change script as below...

If(Employee = Previous(Employee) and NUM(Date) = NUM(Previous(Date))+1,

    Balance+Expenditure-Previous(Balance),

         Balance+Expenditure) as Income,

MK_QSL
MVP
MVP

I have attached updated/corrected file.

Please check and let me know.

Not applicable
Author

Hi Luis,

And many thanks for your reply. I'll try this and let you know if it works.

Many Thanks.

Not applicable
Author

Thanks, I need to consider the balance from the previous date as an income too...