# Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Contributor

## Sorting within a dimension in a pivot table.

Hi,

I am trying to use a sorting function but due to the logic its unable to perform.

I will explain through a example.

Suppose I have two dimensions : Product Family and Customer.

Each product family have different customers. Customers in different product families could be the same.

Eg: Product Family : ABC,  XYZ

Customer : Ford , Nissan

Measure : Sum (Revenue)

I create a pivot table which has Primary Sorting for Product Family by Revenue(descending order). The seconday sorting is for Customer again by Revenue(descending order).

Product Family    Customer     Revenue

ABC                      Ford            \$ 100

Nissan        \$ 200

XYZ                      Ford            \$200

Nissan         \$10

Total of ABC =\$ 300, XYZ = \$210.

So the sorting is Ok.

But what i want is that Ford and Nissan should also rearrange themselves in descending order in their product families.

According to the logic, it sums up the revenue for Ford =\$300, Nissan=\$210 and that is why Ford always appears above Nissan in product families.

How could we accomplish this task ??

So that in ABC the order is Nissan, then Ford. Xyz has the order Ford then Nissan.

1 Solution

Accepted Solutions
Valued Contributor

## Re: Sorting within a dimension in a pivot table.

As gwassenaar‌ explains in Is it possible to sort measure in pivot table using Qlik Sense?, you need to replace the dimension you want to sort by with a dual function. So... your first dimension will be ProductFamily but the second will be " Dual(Customer, Aggr(Sum(Revenue),ProductFamily,Customer)) ". Then you can sort the second dimension numerically in the sort tab.

Review the enclosed file to see the example.

9 Replies
Valued Contributor

## Re: Sorting within a dimension in a pivot table.

As gwassenaar‌ explains in Is it possible to sort measure in pivot table using Qlik Sense?, you need to replace the dimension you want to sort by with a dual function. So... your first dimension will be ProductFamily but the second will be " Dual(Customer, Aggr(Sum(Revenue),ProductFamily,Customer)) ". Then you can sort the second dimension numerically in the sort tab.

Review the enclosed file to see the example.

Honored Contributor III

## Re: Sorting within a dimension in a pivot table.

In Sorting Tab,

Go to Customer - Choose sort by Expression, use Revenue Expression there and apply descending order.

It works.

Valued Contributor

## Re: Sorting within a dimension in a pivot table.

Hi

PFA the attached .qvw for your reference.

Regards

Pratyush

Contributor

## Re: Sorting within a dimension in a pivot table.

Thanks a ton.

It works, but when i try to select something in the filter, the filter shows no value.

It should show me Ford GM etc.

Do you have any suggestions?

Contributor

## Re: Sorting within a dimension in a pivot table.

Thanks Pratyush for the reply. Can you send me a qvf file.

This file doesnot runs on my Qlik Sense

Contributor

## Re: Sorting within a dimension in a pivot table.

Hi Sharddha,

I tried that and simply sorting it out was not solving the problem.

Contributor

## Re: Sorting within a dimension in a pivot table.

Also, when i just try Customer in the expression.

The filter works.

It only doesnot works with the dual expression.

Contributor

## Re: Sorting within a dimension in a pivot table.

So, i got a way to run the QVW file in QVF,

But i could not see any sheet or any visualization.

Can you please send me the expression you used?

Contributor

## Re: Sorting within a dimension in a pivot table.

It works unless you rearrange dimensions in pivot table (e.g. "Customer" before "Product Family")