Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
piter89
Contributor II
Contributor II

The best brand in city and its value in the previous year

Hello,

I have a big problem in set analysis expression. I need the previous year's value for the best brand in town dimension in 2022.

My data:

 

LOAD * inline [
Year   |City  |Brand |Amount
2022   |London|Nike  |9
2022   |London|Adidas|12
2021   |London|Nike  |5
2021   |London|Adidas|1
2022   |Berlin|Nike  |10
2022   |Berlin|Adidas|6
2021   |Berlin|Nike  |46
2021   |Berlin|Adidas|1
] (delimiter is '|');

 

My table:
Zrzut ekranu 2022-12-30 o 11.03.14.png

My expression for last column:

 

=Sum({<Year={'2021'},Brand={'$(=FirstSortedValue(Distinct Brand,-Aggr(Sum({< Year={'2022'} >}Amount),City,Brand)))'}>}Amount)

 

The expression returns the best brand for all cities, but I want the city dimension. The 'where' condition (Brand=) was computed before entering to the row dimension.

 

The expression for Amount column:

 

=Max(Aggr(Sum({< [Year]={'2022'}>}Amount), City, Brand))

 

The expression for the best brand column:

 

=FirstSortedValue(
      Distinct Brand,
      -Aggr(
        Sum({< Year={'2022'} >}Amount),
        City,
        Brand
      )
    )

 


Thanks in advance. 

Labels (4)
2 Replies
Taoufiq_Zarra

@piter89  can you check :

in dimension : City

measures :

best brand ->  FirstSortedValue(Brand, -Aggr(Sum({<Year={"$(=Max(Year))"}>}Amount), Brand,City))

Amount ->  Max({<Year={"$(=Max(Year))"}>}Amount)

Amount 2021 -> Max({<Year={"$(=Max(Year)-1)"}>}Amount)

output:

Taoufiq_Zarra_0-1672402185439.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
piter89
Contributor II
Contributor II
Author

I want to receive the amount in 2021 for the best brand in 2022 in the dimension of the city:
1. Berlin -> correct value is 46, because in 2022 the best brand of the city is Nike and Nike in 2021 had 46
2. London -> correct value is 1, because in 2022 the best brand of the city is Adidas and Adidas in 2021 had 1

Unfortunately, your expression skips the best brand for the city in 2022. 
The last column should show the score for the top brand from 2022 in 2021 in the city (single row).