Quantcast
Channel: SCN : Discussion List - SAP BusinessObjects Web Intelligence
Viewing all articles
Browse latest Browse all 5402

Show Top N rows only (N is derived by ranking on 2 different measures)

$
0
0

Hello Gurus,

 

I've a requirement to show top N rows in a table, but that N is a dynamic which is derived by ranking on 2 different measures. So eventually, we show some rows by ranking on Total and some rows by ranking on Measure 1. (Total = Measure 1 + Measure 2). For some reason I couldn't attach Excel, so attaching the data tables here.

 

I am able to implement the logic for Case 1 by using multiple variables, but the problem is that I need to show rows according to Case 1 or Case 2 in the same table.

 

Case 1: I need to show Top 10 (having Total >= 25,000) and if I have 10 such Names, then I can show upto 3 more Names which have M1 >= 10,000. I can show no more than 13 Names in this case.

 

Case 1
Amt in K (thousands)
NameTotal (M1+M2)M1M2
A01210,000 0210,000
A02186,0000186,000
A0397,00036,00061,000
A0485,000085,000
A0576,4001,40075,000
A0662,840 84062,000
A0759,00032,00027,000
A0853,000053,000
A0946,00066,000(20,000)
A1044,000044,000
A1143,000043,000
A1233,00043,000 (10,000)
A1325,00015,00010,000
A1420,00020,0000
A156,0005,0001,000
A167,0006,0001,000
A176,4002,4004,000
A182,0001,0001,000
A192002000
A20000
A21000
A22000
A23000
A24000
A25000
A26000
A27000
A28000
A29000
A30000

Logic needed for Case 1:

I need to show Top 10 (having Total >= 25,000) and if I have 10 such Names, then I can show upto 3 more Names which have M1 >= 10,000. I can show no more than 13 Names in this case.

Top 10 based on Total
Top 3 based on M1 (excludes top 10 based on Total)
Note: As I mentioned in previous bullet, these are not included in top 3 based on M1, because these rows are already included in top 10 based on Total.

 

Result from Case 1
NameTotal (M1+M2)M1M2
A01210,0000210,000
A02186,0000186,000
A0397,00036,00061,000
A0485,000085,000
A0576,4001,40075,000
A0662,84084062,000
A0759,00032,00027,000
A0853,000053,000
A0946,00066,000(20,000)
A1044,000044,000
A1233,00043,000(10,000)
A1325,00015,00010,000
A1420,00020,0000

 

Case 2: Using the first part of logic in Case 1, if we see that out of Top 10 for Total, we only have 5 Names (with Total more than 25,000), then apart from them, I want to show upto 5 more Names which have M1 >= 5,000. I can show no more than 10 Names in this case.

That means: If only 7 Names have Total >= 25,000, then I can show 3 Names that have M1 >= 5000 or

If only 6 Names have Total >= 25,000, then I can show 4 Names that have M1 >= 5000... and so on.

 

Case 2
Amt in K (thousands)
NameTotal (M1+M2)M1M2
A01210,0000210,000
A02186,0000186,000
A0397,00036,00061,000
A0485,000085,000
A0582,000 10,00072,000
A0623,84084023,000
A0723,000023,000
A082,00012,000(10,000)
A0910,0008,0002,000
A106,0006,0000
A116,0005,0001,000
A127,0006,0001,000
A136,4002,4004,000
A142,0001,0001,000
A152002000
A16000
A17000
A18000
A19000
A20000
A21000
A22000
A23000
A24000
A25000
A26000
A27000
A28000
A29000
A30000

Logic for Case 2:

Using the first part of logic in Case 1, if we see that out of Top 10 for Total, we only have 5 Names (with Total more than 25,000), then apart from them, I want to show upto 5 more Names which have M1 >= 5,000. I can show no more than 10 Names in this case.

That means: If only 7 Names have Total >= 25,000, then I can show 3 Names that have M1 >= 5000 or
If only 6 Names have Total >= 25,000, then I can show 4 Names that have M1 >= 5000... and so on.

Top N (5 in this case) based on Total
Top N (5 in this case) based on M1 (excludes top 10 based on Total)
Note: As I mentioned in previous bullet, these are not included in top N based on M1, because these rows are already included in top N based on Total.

 

Result from Case 2
NameTotal (M1+M2)M1M2
A01210,0000210,000
A02186,0000186,000
A0397,00036,00061,000
A0485,000085,000
A0576,4001,40075,000
A082,00012,000(10,000)
A0910,0008,0002,000
A106,0006,0000
A116,0005,0001,000
A127,0006,0001,000

 

I am able to implement the logic for Case 1 by using multiple variables, but the problem is that I need to show rows according to Case 1 or Case 2 in the same table.

 

Existing Objects: [Name], [Total], [M1] and [M2]

Variables created:

  • v_Total_RankingTop = Rank([Total];Top) (This is to rank based on Total, and why I'm doing Top here? I have to build this whole thing for Ranking from Bottom :-))
  • v_Total_Top10 = If([v_Total_RankingTop] <= 10) Then 1 Else 0 (This is a flag to show 1 if the Name is in Top 10 based on Total, 0 otherwise.)
  • v_Total_25KPlus = If([Total] >= 25000) Then 1 Else 0 (This is a flag to show 1 if the Total >= 25K, 0 otherwise)
  • v_Total_Top10with25KPlus = If([v_Total_Top10]=1 And [v_Total_25KPlus]=1) Then 1 Else 0 (This is a flag to show 1, if the Total >= 25000 and if the row is in Top 10 based on Total)
  • v_M1_ToRank = If([v_Total_Top10]=1) Then 0 Else [M1] (I'll be using for ranking and not M1 directly, because I don't want to rank those M1 values which are already in top 10 based on Total)
  • v_M1_RankingTop10Kplus = If([v_Total_Top10]=0 And [v_M1_ToRank]>=10000) Then Rank([v_M1_ToRank];Top) Else 0 (This is to rank based on v_M1_RankingTop, and why I'm doing Top here? I have to build this whole thing for Ranking from Bottom :-))
  • v_M1_ToRank_Top3with10KPlus = If([v_M1_RankingTop10KPlus] <=3) Then 1 Else 0 (This is a flag to show Top 3 based on v_M1_TopRank)

 

Now, using the above variables, I can accomplish what I need in Case 1 by filtering on the table as [v_Total_Top10with25KPlus] = 1 or [v_M1_ToRank_Top3with10KPlus] = 1 and I'll get 13 rows (10 from ranking based on Total and 3 or less from ranking based on v_M1_ToRank). But what if not all the Top 10 based on Total has Total >= 25,000? I need to go to Case 2, and as you know in N in this case is X+Y (e.g. 9+1 or 8+2 or 7+3 or 6+4 so on till 1+9) where X is the Top N values based on Total having Total > 25,000 and Y is Top 10-X values based on v_M1_ToRank (>= 5000).

 

To get started with finding out what that X, Y can be, I created a formula that gives us X and we can derive Y a 10-X. Great, what do I do after that?

  • v_M1_RankingTopwith5KPlus = If([v_Total_Top10]=0 And [v_M1_ToRank]>=5000) Then Rank([v_M1_ToRank];Top) Else 0 (This is to rank based on v_M1_RankingTop, and why I'm doing Top here? I have to build this whole thing for Ranking from Bottom :-))
  • v_X_TopNwithTotal25KPlus =Max([v_Total_RankingTop] Where ([v_Total_25KPlus]=1)) In Block (This gives us the Max possible value of [v_Total_RankingTop] in a block, so we can at least know how many rows do you we need to show based on Total and v_M1_)
  • v_X,Y = If(10-[v_X_TopNwithTotal25KPlus]<=0) Then "10,3" ElseIf(10-[v_X_TopNwithTotal25KPlus]=1) Then "9,1" ElseIf(10-[v_X_TopNwithTotal25KPlus]=2) Then "8,2" ElseIf(10-[v_X_TopNwithTotal25KPlus]=3) Then "7,3" ElseIf(10-[v_X_TopNwithTotal25KPlus]=4) Then "6,4" ElseIf(10-[v_X_TopNwithTotal25KPlus]=5) Then "5,5" ElseIf(10-[v_X_TopNwithTotal25KPlus]=6) Then "4,6" ElseIf(10-[v_X_TopNwithTotal25KPlus]=7) Then "3,7" ElseIf(10-[v_X_TopNwithTotal25KPlus]=8) Then "2,8" ElseIf(10-[v_X_TopNwithTotal25KPlus]=9) Then "1,9"

 

So, we now at least know, how many values are we showing by ranking based on Total and v_M1_RankingTopwith5KPlus. I need a brake now as my head is spinning and also your help with how to proceed.

 

Hope you'll got the question, any help is appreciated.

 

Thanks,

Mahboob Mohammed


Viewing all articles
Browse latest Browse all 5402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>