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
RobvB
Frequent Visitor

RANKX using a measure

I have a table with sales transactions.

These are item level transactions, so multiple transactions per item/store/date/etc.

First, I want a total per store, so I create this measure:

total $ per store =

CALCULATE(

    SUM('ITK_Retail_AM_ITKRetailTransactionsView'[AALINEAMOUNT]),'ITK_Retail_AM_ITKRetailTransactionsView'[OMOPERATINGUNITNUMBER])

 

So sum AALineAmount for each store (OperatingUnitNumber)

 

Now I want the top 5 of $ per store. So I create another measure:

 

Rank $ per store = rankx(ITK_Retail_AM_ITKRetailTransactionsView, ITK_Retail_AM_ITKRetailTransactionsView[total $ per store])

 

But it returns ‘1’ for each store… What am I missing?

 

RobvB_0-1611008289856.jpeg

 

 

1 ACCEPTED SOLUTION
RobvB
Frequent Visitor

I got it to work. My problem was that I was using the transaction table as the 'main' table, but since I want ranking per store, I should use the store table.

 

Rank Sales Per Store = rankx(ALL(ITK_Retail_AM_OMOperatingUnitEntity), ITK_Retail_AM_ITKRetailTransactionsView[Total Sales Per Store])

View solution in original post

7 REPLIES 7
RobvB
Frequent Visitor

I got it to work. My problem was that I was using the transaction table as the 'main' table, but since I want ranking per store, I should use the store table.

 

Rank Sales Per Store = rankx(ALL(ITK_Retail_AM_OMOperatingUnitEntity), ITK_Retail_AM_ITKRetailTransactionsView[Total Sales Per Store])

Hi @RobvB ,

 

If you get the correct answer yourself, you can mark it as the correct answer.If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

 

Best Regards,
Henry


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

v-henryk-mstf
Community Support
Community Support

Hi @RobvB ,


According to your current description, you want to get the top 5 of $ per store. Try a simple method, use Top N in "Filters on this visual", refer to the following:
Put the field in By value.

v-henryk-mstf_0-1611192876749.jpeg

 

Then, put the Store in the slicer and filter the top5 items corresponding to different stores.

v-henryk-mstf_1-1611192906069.jpeg


If the problem is still not resolved, Please describe the exact requirements and point out detailed error messages. It is best to provide sample pbix file so that I can do the correct test, looking forward to your reply.


Best Regards,
Henry


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

Ashish_Mathur
Super User
Super User

Hi,

Do you want the total sale of the Top 5 items per store?  Share some data and show the expected result. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Basically I want the top 5 of the total sales per store. So I first need to get total sales per store, which I've done by creating the 1st measure, then I want to take the top 5 of that measure, which I tried with the second measure.

Added complexity is that this *has* to be done using direct query only.

 

Date looks like this:

RobvB_0-1611055828434.png

 

Hi,

We should be able to write a measure to do this but i am still not very clear of your expected result.  Share some data (say 50 rows) and show your exact expected result


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

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.