Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Rajkumar
Creator
Creator

FirstSorted Value with filter

Hi everyone,

Greetings,

We have stuck in one set analysis logic,needed help to achieve this.

Store NameRank 1Rank 2Rank 3Rank 4 
WalmartApple LGPanasonicHuawei
TargetApple Panasonichonorakai
CarrefourApple Huaweihonorakai
TescoPanasonicApple Huaweihonor
CostcoLGApple PanasonicHuawei
 Kroger Apple LGHuaweihonor

 

Expression Used: =FirstSortedValue(Brand,-aggr(Sum({<Year=, Month=,Store=,Brand=, Quarter=, Week=,YearWeek=, DATE=, DATENUM={">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} SALES),Brand,store))

when I filter Apple from brand it should show below

Store NameRank 1Rank 2Rank 3Rank 4 
WalmartApple    
TargetApple    
CarrefourApple    
Tesco Apple   
Costco Apple   
 Kroger Apple    

 

But not getting above results.Any help would be appreciated. 

Labels (1)
7 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 

your expression disregards selections in the field brand 

this is why you don't get the results you want 

Rajkumar
Creator
Creator
Author

can you please advise me how to change expression.

sunny_talwar

Can you try this

If(Sum({<Year, Month, Store, Quarter, Week, YearWeek, DATE, DATENUM ={">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} SALES) <> 0,
FirstSortedValue(Brand,-Aggr(Sum({<Year, Month, Store, Brand, Quarter, Week, YearWeek, DATE, DATENUM = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} SALES), Brand, store)))

 

Rajkumar
Creator
Creator
Author

Thank you for reply

Sorry  not working 

sunny_talwar

Would you be able to share a sample where we can see a sample?

Rajkumar
Creator
Creator
Author

Please find the sample data.

 

Store NameBrand SalesDate
WalmartApple 6001/2/2019
TargetApple 7001/2/2019
CarrefourApple 10001/2/2019
TescoPanasonic9001/2/2019
CostcoLG10001/2/2019
 Kroger Apple 7001/2/2019
WalmartLG4001/2/2019
TargetPanasonic5001/2/2019
CarrefourHuawei8501/2/2019
TescoApple 8001/2/2019
Costcoapple8001/2/2019
 Kroger LG5001/2/2019
WalmartPanasonic3001/2/2019
Targethonor2001/2/2019
Carrefourhonor7001/2/2019
TescoHuawei6001/2/2019
CostcoPanasonic6001/2/2019
 Kroger Huawei4001/2/2019
WalmartHuawei1001/2/2019
Targetakai501/2/2019
Carrefourakai3001/2/2019
Tescohonor5001/2/2019
CostcoHuawei5001/2/2019
 Kroger honor2001/2/2019
sunny_talwar

This seems to work

Rank 1 expression

=If(Sum({<[Store Name], Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>}Sales) = Max({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} TOTAL <[Store Name]> Aggr(Sum({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>}Sales), [Store Name], Brand)),
FirstSortedValue({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} Brand,-Aggr(Sum({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} Sales), Brand, [Store Name])))

Rank 2 expression

=If(Sum({<[Store Name], Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>}Sales) = Max({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} TOTAL <[Store Name]> Aggr(Sum({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>}Sales), [Store Name], Brand), 2),
FirstSortedValue({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} Brand,-Aggr(Sum({<[Store Name], Brand, Date, DateNum = {">=$(=$(vCYFromDate))<=$(=$(vCYToDate))"}>} Sales), Brand, [Store Name]), 2))

and so on...