Forum Discussion
Question about Rankx in Matrix table format
- 4 years ago
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!
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 |
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.
- leilei7874 years ago
Helper II
Hi Tamerj1
sorry for the confusion. below is a more realistic sample.
the goal is to rank territory that sold BF product ( And BF product only. i need to show BF3.0, 5.0 and 5.8 but no need to rank these sub-categories, rank still based on the total). so previous ask was still valid. now the problem is that the ranking also need to be dynamic if i select an individual month. For example, if i select Feb, the rank will be based on BF sales in Feb. If i select Jan to April, the rank will be based on BF sales from Jan to Apr....is it possible?
PrimaryGeoCode_c CurrencyCode ShippedUSDAmountNet ProductFamilyCode Month 1101 USD $ 34,342 GVM 1 1101 USD $ 5,332 BF2.5 2 1101 USD $ 355 BF3.8 2 1101 USD $ 3,556 BBQ 3 1101 USD $ 24,522 BF5.0 4 1102 USD $ 3,456 VGN 1 1102 USD $ 7,445 BF5.0 2 1102 USD $ 844 BF3.8 2 1102 USD $ 985 GVM 3 1102 USD $ 8,980 BF3.8 4 1103 USD $ 593 VGN 1 1103 USD $ 4,653 BF3.8 2 1103 USD $ 3,353 BF5.0 2 1103 USD $ 2,432 GVM 3 1103 USD $ 2,556 BF3.8 4 1104 USD $ 4,342 BF5.0 1 1104 USD $ 56,245 BF3.8 2 1104 USD $ 9,543 VGN 2 1104 USD $ 29,405 BBQ 3 1104 USD $ 34,532 BF5.0 4 - tamerj14 years ago
Community Champion
Hi leilei787
In this case, it has to be a measure that is your first solution. Again we will have the problems of your original query hence back to square 1.
So I would advise to go back to your original measure and try to manually hide the ranking for subtotals by minimizing the respective column size to zero width with your mouse. Shifting the row grand total to the left is not possible.
Finally, you can filter out all product families other than "BF" by creating a new table using simple codeTable 2 = FILTER ( 'Table', CONTAINSSTRING ( 'Table'[ProductFamilyCode], "BF" ) )Then use the new table instead for your analysis.
Please let me know if anything further I can help you with.
Have a great day!