Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Franco2
Contributor II
Contributor II

Set analysis conditions between fields

Hi,

I'm trying to obtain the sum of a field but only those where another two fields are related. For example, my data set is something like this:

MonthA MonthB Amount
1 1 10
1 1 20
1 2 30
1 3 40
1 3 20
2 1 10
2 1 40
2 2 50
2 2 10
2 3 20

 

I want to get for every value of Month A the sum of Amount but only where MonthA=MonthB. For example for month 1 will be 30 and for month 2 will be 60. I'm trying to plot this values for all months. The dimension is Month A.

And also for more complex conditions like  MonthA-4<MonthB<MonthA 

I've tried 

sum({<MonthA=P(MonthB)>} Amount)

but doesn't worked.

 

 

 

1 Solution

Accepted Solutions
tresesco
MVP
MVP

You can simply try like:

Sum(If(MonthA=MonthB, Amount))

However, if you want set analysis, you have to have a row identifier from the data itself, like :

Load *, RecNo() As RowID from <>;

And then write set expression like:

Sum({<RowID={"=MonthA=MonthB"}>}Amount)

View solution in original post

4 Replies
abhijitnalekar
Specialist II
Specialist II

Hi @Franco2 ,

Are you looking for the below output?

abhijitnalekar_0-1637216329696.png

 

you can achieve the same by adding new field at script level

if(MonthA=MonthB,Amount)as newAmount,

 

Regards,
Abhijit
keep Qliking...
Help users find answers! Don't forget to mark a solution that worked for you!
tresesco
MVP
MVP

You can simply try like:

Sum(If(MonthA=MonthB, Amount))

However, if you want set analysis, you have to have a row identifier from the data itself, like :

Load *, RecNo() As RowID from <>;

And then write set expression like:

Sum({<RowID={"=MonthA=MonthB"}>}Amount)

Franco2
Contributor II
Contributor II
Author

I've tried it but when i want to use the new field doing a chart it is no usable.

If I write down sum( newAmount) it doesn't show anything.

Franco2
Contributor II
Contributor II
Author

It worked, but now what if I want Month B to be higher than Month A-4.

Isn't it something like

Sum(If(MonthB=">=MonthA-4", Amount))

Sorry I'm kind of new to qlik sense.