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.
I have a table, Orders with ProductName and UnitPrice. I want to create a power BI dashboard where the user chooses the ProductName from a slicer and be able to see 3 products with UnitPrices closest to the selcted product.
ProductName UnitPrice
A | 1000 |
B | 4000 |
C | 1000 |
D | 2000 |
E | 4000 |
F | 1000 |
G | 11000 |
Solved! Go to Solution.
Hi,
I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
RANK function (DAX) - DAX | Microsoft Learn
expected result: =
VAR _selectedproduct =
MAX ( product_slicer[product_name] )
VAR _selectedprice =
MAXX (
FILTER ( ALL ( 'product' ), 'product'[product_name] = _selectedproduct ),
'product'[unit_price]
)
VAR _t =
FILTER ( ALL ( 'product' ), 'product'[product_name] <> _selectedproduct )
VAR _pricediff =
ADDCOLUMNS (
_t,
"@diff", ABS ( CALCULATE ( SUM ( 'product'[unit_price] ) ) - _selectedprice )
)
VAR _diffrank =
ADDCOLUMNS (
_pricediff,
"@diffrank", RANK ( SKIP, _pricediff, ORDERBY ( [@diff], ASC ) )
)
VAR _condition =
SUMMARIZE ( FILTER ( _diffrank, [@diffrank] <= 3 ), 'product'[product_name] )
RETURN
CALCULATE (
SUM ( 'product'[unit_price] ),
KEEPFILTERS ( 'product'[product_name] IN _condition )
)
Hi,
I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
RANK function (DAX) - DAX | Microsoft Learn
expected result: =
VAR _selectedproduct =
MAX ( product_slicer[product_name] )
VAR _selectedprice =
MAXX (
FILTER ( ALL ( 'product' ), 'product'[product_name] = _selectedproduct ),
'product'[unit_price]
)
VAR _t =
FILTER ( ALL ( 'product' ), 'product'[product_name] <> _selectedproduct )
VAR _pricediff =
ADDCOLUMNS (
_t,
"@diff", ABS ( CALCULATE ( SUM ( 'product'[unit_price] ) ) - _selectedprice )
)
VAR _diffrank =
ADDCOLUMNS (
_pricediff,
"@diffrank", RANK ( SKIP, _pricediff, ORDERBY ( [@diff], ASC ) )
)
VAR _condition =
SUMMARIZE ( FILTER ( _diffrank, [@diffrank] <= 3 ), 'product'[product_name] )
RETURN
CALCULATE (
SUM ( 'product'[unit_price] ),
KEEPFILTERS ( 'product'[product_name] IN _condition )
)
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 |
---|---|
60 | |
58 | |
54 | |
36 | |
33 |
User | Count |
---|---|
79 | |
66 | |
45 | |
45 | |
43 |