Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Return calculated value from pivot for set dimension

I am trying to return the results of a calculated value while looking at one set dimension for a pivot. For example I have a pivot looking at the Grade and Gender of a person and want to return the results of only a Gender of M regardless of what the actual Gender is of the line. I have an example of my data below, the expected result always returns the avg rate of the Grade for the M Gender.

GradeGenderAvg RateExpected Result
1F6050
M5050
2M7070
3F8090
M9090

I have tried many different expressions but cannot get any to consistently return the right value.

Thanks,
Matt

1 Solution

Accepted Solutions
Not applicable
Author

Jonathan,

That worked with a slight modification. Below is what I used:

if ( Gender='F',  (sum(  total <Grade> [Avg Rt]) - sum([Avg Rt]))/(count(total<Grade> [Unique ID]) - count( total <Grade,Gender> [Unique ID])) , avg([Avg Rt]))

Unique ID was just another field I had but probably could have used any field in place for that count.

Your formula worked if there were an equal number of people by gender. I was able to get the counts of each gender so that the sum total was divided by the number of 'M' to get the average for the 'M'. This may have been taking a longer way than needed to solve the problem but it worked.

Thank you very much for your help! Greatly Appreciated!

View solution in original post

7 Replies
rubenmarin

Hi Matt,

The expression for expected result should be something like:

Avg({<Gender={'M'}>} Rate)

Not applicable
Author

That is only adding the average to the row with the M Gender and a 0 for all rows with a F Gender.

JonnyPoole
Former Employee
Former Employee

maybe this. but i'd feel better if you post the raw data or the qvw

if(

     Gender = 'M',    sum(  [Avg Rate] ) ,

     if ( Gender = 'F', sum ( {$<Gender={'M'}>} [Avg Rate] ) )

)

Not applicable
Author

Jonathan,


Thanks for your help but that did not work either. Sorry, I am new and do not know how to upload my data.

JonnyPoole
Former Employee
Former Employee

See if this will work:

if ( Gender='F',  sum(  total <Grade> [Avg Rate]) - sum([Avg Rate]) , sum([Avg Rate]))

I tried it with the few rows of data you had in your first post. 

Otherwise, when you reply, go to 'Use Advanced Editor' and then you can attach QVW files or data files.

Not applicable
Author

Jonathan,

That worked with a slight modification. Below is what I used:

if ( Gender='F',  (sum(  total <Grade> [Avg Rt]) - sum([Avg Rt]))/(count(total<Grade> [Unique ID]) - count( total <Grade,Gender> [Unique ID])) , avg([Avg Rt]))

Unique ID was just another field I had but probably could have used any field in place for that count.

Your formula worked if there were an equal number of people by gender. I was able to get the counts of each gender so that the sum total was divided by the number of 'M' to get the average for the 'M'. This may have been taking a longer way than needed to solve the problem but it worked.

Thank you very much for your help! Greatly Appreciated!

JonnyPoole
Former Employee
Former Employee

Great. Kindly close out the thread with the correct/helpful messages.