# Qlik Sense App Development

Contributor

## Aggr Function

Hi Guys,

I am struggling with an aggr function. I think in theory the formula i use should be right but somehow it does not work. I am calculating the driven kilometers of trucks with the following formula: Max (Mileage) - Min (Mileage), and this works fine. Every truck is linked to a department. Now i want to make a pivottable with department as a dimension and a certain timefield (date/week/month etc.) as a dimension.

The measure should calculate for every truck separately the driven kilometers and then calculate the average of all trucks per department. I tried to use this formula but it doesn't work:

Whereby ASSET_NR_LINKED is the dimension for the different trucks.

Anyone who can help me?

1 Solution

Accepted Solutions

## Re: Aggr Function

You mentioned that the expression should work in context with "... certain timefield (date/week/month etc.) ...". This meant you need also to add these time-fields to your aggr. If this didn't work it would be helpful to know with which numbers do you expect which output and which you get from your expression.

- Marcus

6 Replies
MVP

## Re: Aggr Function

Could a single truck land up in more then one Department or is there a one to one relation between Department and truck? If it is not one to one, then may add Department to your Aggr() function

Contributor

## Re: Aggr Function

No a single truck is only linked to one department, so this is not the case.

MVP

## Re: Aggr Function

Have you still tried this?

Contributor

## Re: Aggr Function

Yeah i tried, but the result is exactly the same.

## Re: Aggr Function

You mentioned that the expression should work in context with "... certain timefield (date/week/month etc.) ...". This meant you need also to add these time-fields to your aggr. If this didn't work it would be helpful to know with which numbers do you expect which output and which you get from your expression.

- Marcus

Contributor

## Re: Aggr Function

Thanks Marcus, the addition of the timefield seems to solve the problem