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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
leilei787
Helper II
Helper II

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

 

RankTerritory numberBF3.8BF5.0BF 5.8Total
11111105520
2111255515

 

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

 

leilei787_0-1645115549408.png

 

thank you all!!

 

1 ACCEPTED SOLUTION

Hi @leilei787 
Here is the sample file with the solution https://www.dropbox.com/t/ic5uywEC976ZR0zm

You 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
    Results 
Ranking = 
    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!

View solution in original post

9 REPLIES 9
tamerj1
Super User
Super User

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 requirement

Product Category = 
    IF (
        CONTAINSSTRING ( 'Table'[ProductFamilyCode], "BF" ),
        "BF",
        'Table'[ProductFamilyCode]
    )

Now your report looks like this
Untitle.png
You can use the same link to re-download the file.

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_cCurrencyCodeShippedUSDAmountNetProductFamilyCodeMonth
1101USD2950BF3.8Jan
1101USD1475BF3.8Jan
1101USD2595BF3.8Feb
1101USD1475BF5.0Apr
1105USD1297.5BF3.8March
1105USD1297.5BF5.0Feb
1105USD1450BF5.8Apr
1105USD1297.5BF3.8Jan
1105USD1297.5BF5.0March
1110USD1450BF5.8Jan
1110USD1297.5BF3.8Jan
1110USD1297.5BF5.0Apr
1110USD1450BF5.8Feb
1110USD1700BF5.8March
1110USD1700BF5.8Feb
1110USD1475BF5.0Feb
1106USD5454BF5.0Apr
1106USD24353BF5.8May
1106USD3553BF3.8May
1106USD643BF5.0May
1106USD356BF5.8Apr
1101USD3545BF5.8Jan
1101USD3434BF5.8Jan
1101USD33BF5.8March
1101USD2345BF5.0March
1105USD24334BF5.0March
1105USD235BF5.8March
1105USD33BF3.8Apr

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.

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_cCurrencyCode ShippedUSDAmountNet ProductFamilyCodeMonth
1101USD $                        34,342GVM1
1101USD $                          5,332BF2.52
1101USD $                             355BF3.82
1101USD $                          3,556BBQ3
1101USD $                        24,522BF5.04
1102USD $                          3,456VGN1
1102USD $                          7,445BF5.02
1102USD $                             844BF3.82
1102USD $                             985GVM3
1102USD $                          8,980BF3.84
1103USD $                             593VGN1
1103USD $                          4,653BF3.82
1103USD $                          3,353BF5.02
1103USD $                          2,432GVM3
1103USD $                          2,556BF3.84
1104USD $                          4,342BF5.01
1104USD $                        56,245BF3.82
1104USD $                          9,543VGN2
1104USD $                        29,405BBQ3
1104USD $                        34,532BF5.04

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 code

 

Table 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!

tamerj1
Super User
Super User

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. 

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 right
 
leilei787_1-1645122424722.png

 

here 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_cCurrencyCodeShippedUSDAmountNetProductFamilyCode
1101USD2950BF3.8
1101USD1475BF3.8
1101USD2595BF3.8
1101USD1475BF5.0
1105USD1297.5BF3.8
1105USD1297.5BF5.0
1105USD1450BF5.8
1105USD1297.5BF3.8
1105USD1297.5BF5.0
1110USD1450BF5.8
1110USD1297.5BF3.8
1110USD1297.5BF5.0
1110USD1450BF5.8
1110USD1700BF5.8
1110USD1700BF5.8
1110USD1475BF5.0
1106USD5454BF5.0
1106USD24353BF5.8
1106USD3553BF3.8
1106USD643BF5.0
1106USD356BF5.8
1106USD665BF5.8

Hi @leilei787 
Here is the sample file with the solution https://www.dropbox.com/t/ic5uywEC976ZR0zm

You 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
    Results 
Ranking = 
    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

 

your method works thank you!...but i need to make it a little complicated....

 

in the last dataset, i have product category BF3.8, BF5.0 and BF5.8. what if i have more product families? but in the end, i just want to rank BF3.8, BF 5.0 and BF5.8?

 

I know i need to modify Total amount formula you wrote....but keep failing

 

so again...same result needed for BF category only. thank you so much!

 

PrimaryGeoCode_cCurrencyCodeShippedUSDAmountNetProductFamilyCode
1101USD2950BF3.8
1101USD1475BF3.8
1101USD2595BF3.8
1101USD1475BF5.0
1105USD1297.5BF3.8
1105USD1297.5BF5.0
1105USD1450BF5.8
1105USD1297.5BF3.8
1105USD1297.5BF5.0
1110USD1450BF5.8
1110USD1297.5BF3.8
1110USD1297.5BF5.0
1110USD1450BF5.8
1110USD1700BF5.8
1110USD1700BF5.8
1110USD1475BF5.0
1106USD5454BF5.0
1106USD24353BF5.8
1106USD3553BF3.8
1106USD643BF5.0
1106USD356BF5.8
1101USD3545GVM
1101USD3434GVM
1101USD33GVM
1101USD2345GVM
1105USD24334GVM
1105USD235BBQ
1105USD33BBQ
1105USD3555BBQ
1105USD33BBQ
1110USD664BBQ
1110USD2455BBQ
1110USD433BBQ
1110USD4325VGN
1110USD4533VGN
1110USD2456VGN
1110USD3324VGN
1106USD356VGN
1106USD35267VGN
1106USD868VGN
1106USD907VGN
1106USD589VGN

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors