cancel
Showing results for
Did you mean:
Anonymous
Not applicable

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
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
)``````

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.

5 REPLIES 5
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
)``````

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.

Microsoft

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!

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

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]

!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Microsoft

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!