Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi
I have the following dimension table:
CustomerID | Age bucket | Gender |
1 | 30 | M |
2 | 40 | F |
3 | 40 | M |
4 | 30 | M |
5 | 20 | F |
6 | 60 | M |
And the following sales table:
SalesID | CustomerID | Sale | Date |
1 | 1 | 50 | 01/06/2021 |
2 | 1 | 50 | 02/03/2021 |
3 | 2 | 20 | 05/03/2021 |
4 | 3 | 100 | 02/04/2021 |
5 | 3 | 50 | 25/05/2021 |
6 | 3 | 50 | 11/03/2021 |
7 | 4 | 10 | 14/03/2021 |
8 | 5 | 40 | 02/01/2021 |
9 | 6 | 150 | 15/04/2021 |
10 | 6 | 100 | 02/02/2021 |
I want to be able to create a top N list by customer sales (top n is based on a slicer and sales data is filtered by a slicer).
But then return those top N customers age bands in a histogram.
Example: Top N = 2
Top customers:
CustomerID | Total sales |
3 | 200 |
6 | 250 |
1 | 100 |
Age distribution of Top N | |
Count: | Age |
2 | 30 |
1 | 60 |
So far I can rank the total customer sales, but then if I try and count the ages, the count equals the total sales items instead of grouping by customer ID.
@rosh although you already have great solutions, some of them will not show the Total Sales of TopN correctly. Here is my solution and all the measures required to make it work:
Total = SUM( SALES[Sale] )
Top n Customers =
CALCULATE (
[TOTAL],
KEEPFILTERS (
TOPN (
[Parameter Value],
ALLSELECTED ( CUSTOMER ),
[Total Sales],
DESC
)
)
)
Top n count =
VAR __table =
ADDCOLUMNS (
ALLSELECTED ( CUSTOMER[CustomerID] ),
"@TopN", [Top n Customers]
)
RETURN
COUNTX ( __table, [@TopN] )
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Thanks, this almost works, but the problem is that my sales detail has more than one sales row per customer. So the above solution counts the age band of the same customer more than once.
Any advice?
I didn't get your point; I used the above mockup dataset, which also containes more than one row for each customer.
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
User | Count |
---|---|
128 | |
108 | |
99 | |
65 | |
62 |
User | Count |
---|---|
136 | |
113 | |
102 | |
71 | |
60 |