Forum Discussion
TOPN DAX function Issue
Dear Power BI community ,
I am trying to solve a problem related to TOPN DAX function. I want to show list of top 3 products based on their net sales. When I represents products and respective net sales values in a table, and filter the table based on TOPN products, then the total value is showing the correct value.
But when I create a dax measure using TOPN function I am getting different Total result. Though, I am not using any other filters in the report. A screen shot of the example and below DAX measure I am using is provided in the below table format.
How I can correct TOTAL NET SALES VALUES of TOP 3 products by using DAX measure ?
= SUMX(
TOPN(
3,
SUMMARIZE(
Sales,
Sales[ProductKey],
"NetSales", SUM(InternetSales[SalesAmount])
),
[NetSales], DESC
),
[NetSales]
)
Hi ankbaner -You're absolutely right to observe the discrepancy
TopN Net Sales =
VAR TopProducts =
TOPN(
3,
ADDCOLUMNS(
VALUES(Sales[ProductKey]),
"NetSales", CALCULATE(SUM(InternetSales[SalesAmount]))
),
[NetSales], DESC
)
RETURN
SUMX(
TopProducts,
[NetSales]
)Hope this works.
6 Replies
- rajendraongole1Super User
Hi ankbaner -You're absolutely right to observe the discrepancy
TopN Net Sales =
VAR TopProducts =
TOPN(
3,
ADDCOLUMNS(
VALUES(Sales[ProductKey]),
"NetSales", CALCULATE(SUM(InternetSales[SalesAmount]))
),
[NetSales], DESC
)
RETURN
SUMX(
TopProducts,
[NetSales]
)Hope this works.
- ankbanerRegular Visitor
Hi,
Thank you for contributing to create solution. The given formula did not help to get the actual result. The outcome of the formula still shows difference compared to Top n Filter
- v-sdhruvCommunity Support
Hi ankbaner ,
Just wanted to check if you had the opportunity to review the information provided by rajendraongole1 .
If his response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you. - v-sdhruvCommunity Support
Hi @ankbaner ,
Just wanted to check if you had the opportunity to review the information provided by @rajendraongole1 .
If his response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you. - v-sdhruvCommunity Support
Just wanted to check if you had the opportunity to review the information provide?.
If his response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.