Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi guys,
I would like to create a TOPN measure that sums up the revenues generated by the 2 most high-selling products. However, my table (a simplified version below) contains duplicates.
Is it possible to create a TOPN measure for revenue (column 3) that recognizes duplicates by product ID (column 1)?
Input:
Product ID | Revenue EURO |
A | 100 |
A | 100 |
B | 50 |
C | 20 |
D | 10 |
My desired output would be a TOPN measure that gives the result 250 for the top 2 most high selling products, in this instance: A generates 200 EURO and B 50 EURO.
So the measure should on the one hand recognize duplicates (here: A) but still summarize the revenue for duplicate products.
Hope that is not too confusing!
Solved! Go to Solution.
Please try this expression in a measure to get your desired result.
Top 2 Sum =
VAR summary =
ADDCOLUMNS (
VALUES ( 'Table'[Product ID] ),
"@total", CALCULATE ( SUM ( 'Table'[Revenue EURO] ) )
)
RETURN
SUMX ( TOPN ( 2, summary, [@total], DESC ), [@total] )
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi @Anonymous ,
According to my understanding, you want to sum the top2 values when there are duplicate values, right?
You could use the following formula:
rank =
RANKX (
ALLSELECTED ( 'Table' ),
CALCULATE ( SUM ( 'Table'[sumColumn] ) ),
,
DESC,
DENSE
)
sumTop2 =
CALCULATE (
SUM ( 'Table'[Revenue EURO] ),
FILTER ( ALL ( 'Table' ), [rank] <= 2 )
)
My visualization looks like this:
Is the result what you want? If not, please upload some data samples and expected output.
Please do mask sensitive data before uploading.
Best Regards,
Eyelyn Qin
Please try this expression in a measure to get your desired result.
Top 2 Sum =
VAR summary =
ADDCOLUMNS (
VALUES ( 'Table'[Product ID] ),
"@total", CALCULATE ( SUM ( 'Table'[Revenue EURO] ) )
)
RETURN
SUMX ( TOPN ( 2, summary, [@total], DESC ), [@total] )
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Hi @Anonymous
Create a measure as
Measure = CALCULATE(SUMX(TOPN(2,VALUES('Table'[Revenue]),'Table'[Revenue],DESC),'Table'[Revenue]))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Regards,
Pranit
Hope it resolves your issue? Did I answer your question? Mark my post as a solution! Appreciate your Kudos, Press the thumbs up button!! Linkedin Profile |
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
79 | |
58 | |
35 | |
35 |
User | Count |
---|---|
99 | |
59 | |
56 | |
46 | |
40 |