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
Anonymous
Not applicable

TOP N Customers by profit (N is a measure output)

Hello PowerBI Community,

 

What I have in mind is a measure that reorders the customer list according to the profit I make off of them. The measure then filters out TOP X customers (the X is from a different measure) and displays just them in a table. Seems pretty simple but I could not find any info on this. Could you please help a fellow beginner with writing a formula? Or do I have to make a custom table inside PowerBi?

 

Thanks in advance,

Zenons.

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Please see this video on how to do this with the TOPN function.

 

https://www.youtube.com/watch?v=wKfPS1yZfE0

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

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


View solution in original post

v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

According to my understanding, you want to dynamically display topN data, right?

Here are my data sample:

8.19.4.PNG

You could use the following formula :

dynamicTOPN =
VAR rankMeasure =
    RANKX ( ALL ( Sort ), CALCULATE ( MAX ( 'Sort'[Profit ] ) ) )
RETURN
IF ( SELECTEDVALUE ( forN[N] ) >= rankMeasure, 1, 0 )

My visualization looks like this after applying filter:

8.19.5.png

Is the result what you want? If you have any questions, please upload some data samples and expected output.

Please do mask sensitive data before uploading.

 

Best Regards,

Eyelyn Qin

View solution in original post

7 REPLIES 7
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

According to my understanding, you want to dynamically display topN data, right?

Here are my data sample:

8.19.4.PNG

You could use the following formula :

dynamicTOPN =
VAR rankMeasure =
    RANKX ( ALL ( Sort ), CALCULATE ( MAX ( 'Sort'[Profit ] ) ) )
RETURN
IF ( SELECTEDVALUE ( forN[N] ) >= rankMeasure, 1, 0 )

My visualization looks like this after applying filter:

8.19.5.png

Is the result what you want? If you have any questions, please upload some data samples and expected output.

Please do mask sensitive data before uploading.

 

Best Regards,

Eyelyn Qin

Anonymous
Not applicable

@v-eqin-msft What do I do if my Profit Column is a calculated column, and I want it to change according to a date slicer?

Anonymous
Not applicable

Screenshot (3).png

Thanks for the help @v-eqin-msft. I just have a slight issue - my profit by client is not a column, it is a measure. What can I do to fix that? 

 

Hi @Anonymous ,

 

Change your var rankmeasure  to the 

 

var rankmeasure  = RANKX(ALL (SALES) , [Total Profit])\

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Anonymous
Not applicable

@harshnathani At first it worked, but then I realized that something was wrong. It still does not work because my SALES table is a table with thousands of invoices and DAX ranks the invoices, not the particular clients. What do you suggest?

Anonymous
Not applicable

Wow @harshnathani , it was that simple, thanks a lot!

mahoneypat
Employee
Employee

Please see this video on how to do this with the TOPN function.

 

https://www.youtube.com/watch?v=wKfPS1yZfE0

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

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
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.