# Qlik Support Discussions

Discussion Board for collaboration related to Qlik Support.

Highlighted
New Contributor

## How to use sum and first sorted value together

Hi,

I have used first sorted function to find out first sales of month for a particular region/state, In Pivot chart I need to add each state value( result of : firstsortedvalue(Sales, Txn_Dt)) to the country level and continent level or few other dimensions.

When I try the following expression, it is resulting Null

sum(FirstSortedValue(Sales,Txn_Dt) .

It would be great if any could share your thoughts if you aware of such scenarios how to handle them.

Thanks

Sangeeth

1 Solution

Accepted Solutions
MVP

## Re: How to use sum and first sorted value together

You can't nest aggregation functions directly like that. You can do this:

`sum(Aggr(FirstSortedValue(Sales,Txn_Dt), <Some dimension>))`

Where <Some dimension> are one or more fields by which the FirstSortedValue will be calculated.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
4 Replies
Honored Contributor II

## Re: How to use sum and first sorted value together

Hi,
i noted in your expression one bracket is missing: sum(FirstSortedValue(Sales,Txn_Dt) )
anyway how does your pivot chart looks like and what's your expected result?
could you share an example with data?

MVP

## Re: How to use sum and first sorted value together

You can't nest aggregation functions directly like that. You can do this:

`sum(Aggr(FirstSortedValue(Sales,Txn_Dt), <Some dimension>))`

Where <Some dimension> are one or more fields by which the FirstSortedValue will be calculated.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
New Contributor

## Re: How to use sum and first sorted value together

Hi,

I am glad for your message, Thanks for correcting syntax. I have managed to find the solution.

If we want to use sum and Firstsortedvalue

Sol: Sum(Aggr(FirstSortedValue(Value,<SortingObject>),<Dimension1>,<Dimension2>))

New Contributor

## Re: How to use sum and first sorted value together

If we have cyclic groups in Chart, do we need to mention all dimensions which involved in cyclic groups in place of dimensions?

Thanks

Sangeeth