Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
alvarogh27
Contributor II
Contributor II

Set analysis: Pivot table and First Sorted Value and Aggr Function

Dear Friends:

I have a question about the utilization of First Sorted Value combinated with Aggr Función in a PivotTable.

I have 2 cases:

1-To know the best agent Agent with more sales for month and rute.

2-To know the sum of sales of best agent for month and route.

In the first case, i solve with the expression into the PivotTable:

FirstSortedValue(AGENT, -(Aggr(Sum(SALES),REGION, RUTE, MONTH,YEAR)))

It's like this:

    

AÑOMESRUTARUTA-01RUTA-02RUTA-03RUTA-04RUTA-05RUTA-06RUTA-07RUTA-08RUTA-09
2015ENERO AGENT 3AGENT 6AGENT 22AGENT 25AGENT 9AGENT 25AGENT 1AGENT 7AGENT 25
2015FEBRERO AGENT 3AGENT 11AGENT 19AGENT 5AGENT 6AGENT 14AGENT 9AGENT 22AGENT 24
2015MARZO AGENT 12AGENT 22AGENT 2AGENT 10AGENT 13AGENT 16AGENT 10AGENT 17AGENT 11
2015ABRIL AGENT 1AGENT 8AGENT 12AGENT 8AGENT 6AGENT 13AGENT 6AGENT 1AGENT 19
2015MAYO AGENT 0AGENT 16AGENT 9AGENT 24AGENT 21AGENT 4AGENT 16AGENT 25AGENT 25
2015JUNIO AGENT 8AGENT 16AGENT 14AGENT 5AGENT 18AGENT 10AGENT 2AGENT 16AGENT 3
2015JULIO AGENT 17AGENT 1AGENT 7AGENT 11AGENT 25AGENT 21AGENT 6AGENT 11AGENT 16
2015AGOSTO AGENT 25AGENT 22AGENT 3AGENT 0AGENT 20AGENT 7AGENT 4AGENT 18AGENT 0
2015SEPTIEMBREAGENT 3AGENT 7AGENT 5AGENT 25AGENT 15AGENT 3AGENT 2AGENT 16AGENT 1
2015OCTUBRE AGENT 11AGENT 3AGENT 22AGENT 0AGENT 1AGENT 8AGENT 17AGENT 3AGENT 5
2015NOVIEMBREAGENT 25AGENT 21AGENT 18AGENT 5AGENT 6AGENT 11AGENT 17AGENT 21AGENT 14
2015DICIEMBRE AGENT 18AGENT 9AGENT 11AGENT 0AGENT 21AGENT 0AGENT 9AGENT 15AGENT 24
2016ENERO AGENT 5AGENT 25AGENT 20AGENT 12AGENT 20AGENT 0AGENT 16AGENT 22AGENT 17
2016FEBRERO AGENT 7AGENT 12AGENT 8AGENT 8AGENT 4AGENT 18AGENT 4AGENT 21AGENT 11
2016MARZO AGENT 7AGENT 10AGENT 16AGENT 4AGENT 22AGENT 22AGENT 8AGENT 11AGENT 21
2016ABRIL AGENT 21AGENT 21AGENT 5AGENT 11AGENT 22AGENT 14AGENT 0AGENT 14AGENT 15
2016MAYO AGENT 14AGENT 3AGENT 18AGENT 25AGENT 21AGENT 13AGENT 6AGENT 18AGENT 7
2016JUNIO AGENT 10AGENT 15AGENT 5AGENT 6AGENT 9AGENT 1AGENT 23AGENT 8AGENT 7
2016JULIO AGENT 2AGENT 18AGENT 5AGENT 1AGENT 5AGENT 11AGENT 21AGENT 18AGENT 9
2016AGOSTO AGENT 3AGENT 10AGENT 6AGENT 0AGENT 23AGENT 19AGENT 12AGENT 15AGENT 6

In the other case:

I tried this:

1-Sum({$<AGENT={'=FirstSortedValue(AGENT,  -(Aggr(Sum(SALES),REGION, RUTE, MONTH,YEAR))))'}>} SALES)

2-Sum({$<AGENT={"=FirstSortedValue(AGENT,  -(Aggr(Sum(SALES),REGION, RUTE, MONTH,YEAR))))"}>} SALES)

3-Sum({$<AGENT={'$(=FirstSortedValue(AGENT,  -(Aggr(Sum(SALES),REGION, RUTE, MONTH,YEAR)))))'}>} SALES)


It does'nt work anything of 3 expression.

I don't understand if it works the FirsSortedValue Part alone, i can't use like a set analysis in the second case.


Thank's

1 Solution

Accepted Solutions
sunny_talwar

See if this is what you want

Capture.PNG

=Sum(Aggr(If(AGENTE = FirstSortedValue(TOTAL <REGION, FECHA, MES, RUTA> AGENTE, -Aggr(Sum(SALES), REGION, FECHA, MES, RUTA, AGENTE)), Sum(SALES)), REGION, FECHA, MES, RUTA, AGENTE))

View solution in original post

6 Replies
sunny_talwar

Have you tried this?

Max(Aggr(Sum(SALES), REGION, RUTE, MONTH, YEAR))

alvarogh27
Contributor II
Contributor II
Author

Hi Sunny:

Thanks for your faster answer.

I tried this and it doesn't work.

I use FirstSortedValue because it's possible  may be there are several agent with the same sales and I only want one.

In the first case it's working, but when i insert this part inside the second case....it doesn't work.

sunny_talwar

I am not entirely sure I understand... would you be able to share some raw data with the expected output from it to get a better feel for your question?

alvarogh27
Contributor II
Contributor II
Author

I send you a *.qvw and *.xls whith the data.

sunny_talwar

See if this is what you want

Capture.PNG

=Sum(Aggr(If(AGENTE = FirstSortedValue(TOTAL <REGION, FECHA, MES, RUTA> AGENTE, -Aggr(Sum(SALES), REGION, FECHA, MES, RUTA, AGENTE)), Sum(SALES)), REGION, FECHA, MES, RUTA, AGENTE))

alvarogh27
Contributor II
Contributor II
Author

IT' WORKS!!!!!

Thanks very match.

Now I just have to understand.