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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

rankx start with 2

I have a matrix table with 2 fields:  states ,e.g - Texas, California and products sell in this states. this two tables are connected trhough fact table. I'm doing a ranking where the main is order the sum of sale per state and per product, but for some reason the ranking for some states is starting with 2 or even duplicate.

 

 

RANKX(all('fid dim_product'),[value],,DESC,Dense)

 

 

 
I've tried to put another all for dim_state, but it didn't work. For some reason,, in some states the formula its correct, but for another ones it starts with 2 or duplicate the values even without duplicate of the metric
1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try to refer to my formulas.

 

//Measure
__SUM = 
SUMX(
    FILTER( ALL(Sheet3), [State] = MAX([State]) && [Product] = MAX([Product]) ),
    [qty]
)
//Measure
Rank = 
RANKX(
    FILTER( ALLSELECTED(Sheet3), [State] = MAX([State]) ),
    [__SUM],
     , ASC, Dense
)

 

v-lionel-msft_0-1608535806734.png

If it's incorrect, please provide the sample data of your tables(We need sample data for fact table and dimension table).

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

5 REPLIES 5
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try to refer to my formulas.

 

//Measure
__SUM = 
SUMX(
    FILTER( ALL(Sheet3), [State] = MAX([State]) && [Product] = MAX([Product]) ),
    [qty]
)
//Measure
Rank = 
RANKX(
    FILTER( ALLSELECTED(Sheet3), [State] = MAX([State]) ),
    [__SUM],
     , ASC, Dense
)

 

v-lionel-msft_0-1608535806734.png

If it's incorrect, please provide the sample data of your tables(We need sample data for fact table and dimension table).

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

mahoneypat
Employee
Employee

If you can share a link to your pbix file or paste your example data in a reply (so it can be easily copied), a specific solution can be suggested.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

hi @mahoneypat , this is my data behaviour. sometimes the ranking works, sometimes not. I think this should hapeen due to context filter. the tables states and products are separeted 


State

    California      qty          myranking
         Iphone     1500       2
         Galaxy       1279      2

         Huawei     950         3

    Texas             qty          myranking
         Iphone     800         1
         Galaxy      279         2

         Huawei     90           3

thanks for help me

amitchandak
Super User
Super User

@Anonymous , check do you have null/blank  value in fid dim_product or a value missing in fid dim_product which there in the table having columns for measure [value]

mahoneypat
Employee
Employee

If you share some example data, a specific solution can be suggested.  You should use RANKX over a column, not the whole table.  That removes all the filters from that table; the state with 2 probably doesn't have sales for the top product.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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