Forum Discussion
Question about Rankx in Matrix table format
Hello
i am trying to use Rankx and matrix table to setup a format in BPI like this
| Rank | Territory number | BF3.8 | BF5.0 | BF 5.8 | Total |
| 1 | 1111 | 10 | 5 | 5 | 20 |
| 2 | 1112 | 5 | 5 | 5 | 15 |
The closest format i can think of is to use Matrix table. The problem is that Rankx can only be placed as VALUES...so here is what i have now below.
Question 1) any way to move the ranking to the row? so before the territory number column?
Question 2) how to get rid of ranking for each sub product category. i only want to know $$, dont really care about how they rank individually. i do want to keep the overall ranking though
thank you all!!
Hi leilei787
Here is the sample file with the solution https://www.dropbox.com/t/ic5uywEC976ZR0zmYou need to create two columns.
Total Amount = VAR CurrentCode = 'Table'[PrimaryGeoCode_c] VAR CurrentCodeTable = FILTER ( 'Table', 'Table'[PrimaryGeoCode_c] = CurrentCode ) VAR Results = SUMX ( CurrentCodeTable, 'Table'[ShippedUSDAmountNet] ) RETURN ResultsRanking = RANKX ( 'Table', 'Table'[Total Amount], , DESC, Dense )Then create your measure
Shipping Net = SUM ('Table'[ShippedUSDAmountNet] )I hope this satisfies your requirement. If so please consider marking this reply as "Accepted" solution. Thank you!
9 Replies
- tamerj1Community Champion
Hi leilei787
Best to create a new calculated column to rank your products. Then you can just drag it to rows or otherwise use the following measure which will show blanks for any higher granularity.
IF (
HASONEVALUE ( Producr Key ),
VALUES ( "RANKX calculation" )
)
If you just want to to hide the subcategories just resize the column using the mouse to zero width.
it would be great if you can share a sample file to assesst further.
- leilei787Helper II
thank you! somehow i could not get it work even i use calculated column. here is what i did
i created a calculated column, here is my formula:
Bflex TM Ranking3 = rankx(ALLSELECTED('vw_fact_ShippingDetailWithReturns (Commercial)'[PrimaryGeoCode_c]),[Total Shipping Net])i am able to put the rank on the ROWs....however, in the matrix format, it is still not working righthere are the sample data:
so ideally i want to have the rank first, then territory numbers, product family on the column. Rank by total sales, not individual product.
PrimaryGeoCode_c CurrencyCode ShippedUSDAmountNet ProductFamilyCode 1101 USD 2950 BF3.8 1101 USD 1475 BF3.8 1101 USD 2595 BF3.8 1101 USD 1475 BF5.0 1105 USD 1297.5 BF3.8 1105 USD 1297.5 BF5.0 1105 USD 1450 BF5.8 1105 USD 1297.5 BF3.8 1105 USD 1297.5 BF5.0 1110 USD 1450 BF5.8 1110 USD 1297.5 BF3.8 1110 USD 1297.5 BF5.0 1110 USD 1450 BF5.8 1110 USD 1700 BF5.8 1110 USD 1700 BF5.8 1110 USD 1475 BF5.0 1106 USD 5454 BF5.0 1106 USD 24353 BF5.8 1106 USD 3553 BF3.8 1106 USD 643 BF5.0 1106 USD 356 BF5.8 1106 USD 665 BF5.8 - tamerj1Community Champion
Hi leilei787
Here is the sample file with the solution https://www.dropbox.com/t/ic5uywEC976ZR0zmYou need to create two columns.
Total Amount = VAR CurrentCode = 'Table'[PrimaryGeoCode_c] VAR CurrentCodeTable = FILTER ( 'Table', 'Table'[PrimaryGeoCode_c] = CurrentCode ) VAR Results = SUMX ( CurrentCodeTable, 'Table'[ShippedUSDAmountNet] ) RETURN ResultsRanking = RANKX ( 'Table', 'Table'[Total Amount], , DESC, Dense )Then create your measure
Shipping Net = SUM ('Table'[ShippedUSDAmountNet] )I hope this satisfies your requirement. If so please consider marking this reply as "Accepted" solution. Thank you!
- tamerj1Community Champion
Hi leilei787
A slicer will do. But to make it practical I created a new column which I called "Product Category" that returns "BF" for any family code that contains "BF". Code can be adjusted as per your requirementProduct Category = IF ( CONTAINSSTRING ( 'Table'[ProductFamilyCode], "BF" ), "BF", 'Table'[ProductFamilyCode] )Now your report looks like this
You can use the same link to re-download the file.- leilei787Helper II
hi Tamerj1, one more question, your previous solution works beautifully! thank you!
the only issue now i have is that the ranking works, let's say if i look at 2021 as a whole. but if i select, Jan or March, the ranking wont start from 1,2,3....i think the reason is because the "Total Amount" formula is looking at acumulated amount of what each territory sold. if i select an individual month, ranking remains the same....is there a way to re-rank if i select individual month?
PrimaryGeoCode_c CurrencyCode ShippedUSDAmountNet ProductFamilyCode Month 1101 USD 2950 BF3.8 Jan 1101 USD 1475 BF3.8 Jan 1101 USD 2595 BF3.8 Feb 1101 USD 1475 BF5.0 Apr 1105 USD 1297.5 BF3.8 March 1105 USD 1297.5 BF5.0 Feb 1105 USD 1450 BF5.8 Apr 1105 USD 1297.5 BF3.8 Jan 1105 USD 1297.5 BF5.0 March 1110 USD 1450 BF5.8 Jan 1110 USD 1297.5 BF3.8 Jan 1110 USD 1297.5 BF5.0 Apr 1110 USD 1450 BF5.8 Feb 1110 USD 1700 BF5.8 March 1110 USD 1700 BF5.8 Feb 1110 USD 1475 BF5.0 Feb 1106 USD 5454 BF5.0 Apr 1106 USD 24353 BF5.8 May 1106 USD 3553 BF3.8 May 1106 USD 643 BF5.0 May 1106 USD 356 BF5.8 Apr 1101 USD 3545 BF5.8 Jan 1101 USD 3434 BF5.8 Jan 1101 USD 33 BF5.8 March 1101 USD 2345 BF5.0 March 1105 USD 24334 BF5.0 March 1105 USD 235 BF5.8 March 1105 USD 33 BF3.8 Apr - tamerj1Community Champion
Hi leilei787
Would you help me out please I'm a little confused.
Do you need to consider other product families in the ranking?
"OR"
Do you mean we need to filter out all records that belongs to product families other than BF families. Then do the ranking?
Will the ranking be based on ever total amount, anual total amount or monthly total amount? As this is a calculated column and we have to clearly understand at which granularity our code shall be based on.
Based on the current code, when you select a month you will see the amounts aggregated by month but ranking will not change unless you updated your source data.
If you can share your sample file updated with more data and more rates that would be great.