Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
cryspezz
Frequent Visitor

Lookup Closest Suggested Price

Hello,

 

I am working on a project that helps our Pricing team identify areas where a customer isn't following our suggested pricing.

 

We offer a suggested pricing structure to the wholesaler, which isn't always necessarily followed.  I need to be able to show the nearest Suggested Price (rounding up for all pricing unless it's above the highest price, and in that case rounding down) for that particular day, customer, product, side by side with the Sales Price.  I've tried a TOPN formula, but I can't seem to get it to work.

 

Sales Fact Table:

DateCustomerProduct Sales Price Units Measure Output:
Suggested Price 
 Measure Output: Difference in Actual vs Suggested 
1/1/2022XA $        21.9910 $                             20.99 $                                    (1.00)
1/3/2022XA $        20.0035 $                             20.99 $                                0.99
1/7/2022XA $        19.5060 $                             19.99 $                                0.49
1/15/2022XA $        17.99100 $                             19.99 $                                2.00
1/21/2022XA $        16.995 $                             16.99 $                                    -  
1/31/2022XA $        15.9955 $                             15.99 $                                    -  

 

Suggested Price Table:

DateCustomerProductQtySuggested Price
1/1/2022XA120.99
1/1/2022XA5019.99
1/3/2022XA120.99
1/3/2022XA5019.99
1/7/2022XA120.99
1/7/2022XA5019.99
1/15/2022XA120.99
1/15/2022XA5019.99
1/21/2022XA116.99
1/21/2022XA5015.99
1/31/2022XA116.99
1/31/2022XA5015.99
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@cryspezz 

you can try this

Measure = 
VAR _low=maxx(FILTER('Suggested Price','Suggested Price'[Date]=max('Sales'[Date])&&'Suggested Price'[Customer]=max(Sales[Customer])&&'Suggested Price'[Product]=max(Sales[Product])&&'Suggested Price'[Suggested Price]<=max(Sales[ Sales Price ])),'Suggested Price'[Suggested Price])
VAR _high=minx(FILTER('Suggested Price','Suggested Price'[Date]=max('Sales'[Date])&&'Suggested Price'[Customer]=max(Sales[Customer])&&'Suggested Price'[Product]=max(Sales[Product])&&'Suggested Price'[Suggested Price]>=max(Sales[ Sales Price ])),'Suggested Price'[Suggested Price])
VAR _diff1=ABS(_low-max(Sales[ Sales Price ]))
VAR _diff2=ABS(_high-max(Sales[ Sales Price ]))
return if (_diff1<=_diff2,_low,_high)


Measure 2 = [Measure]-max(Sales[ Sales Price ])

 

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

Ideally you should solve this with a calculated column formula in the Sales Fact table rather than with a measure.  If you are OK with my approach, then let me know.  Also, shouldn't the answer in row 2 of the dataset be 19.99 (35 is closer to 50 than it is to 1).  Please clarify.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

 

I'd like to hear more about the calculated column approach.  The suggested qty can be ignored as the customer can technically sell at any price they'd like.

Hi,

This calculated column formula returns the suggested price where quantity is 1 on the suggested_price table.

=CALCULATE(MAX(Suggested_price[Suggested Price]),FILTER(Suggested_price,Suggested_price[Date]=EARLIER(Sales[Date])&&Suggested_price[Customer]=EARLIER(Sales[Customer])&&Suggested_price[Product]=EARLIER(Sales[Product])&&Suggested_price[Qty]=1))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

 

This calculated column looks like it is giving us the highest suggested price and not the closest.

ryan_mayu
Super User
Super User

@cryspezz 

you can try this

Measure = 
VAR _low=maxx(FILTER('Suggested Price','Suggested Price'[Date]=max('Sales'[Date])&&'Suggested Price'[Customer]=max(Sales[Customer])&&'Suggested Price'[Product]=max(Sales[Product])&&'Suggested Price'[Suggested Price]<=max(Sales[ Sales Price ])),'Suggested Price'[Suggested Price])
VAR _high=minx(FILTER('Suggested Price','Suggested Price'[Date]=max('Sales'[Date])&&'Suggested Price'[Customer]=max(Sales[Customer])&&'Suggested Price'[Product]=max(Sales[Product])&&'Suggested Price'[Suggested Price]>=max(Sales[ Sales Price ])),'Suggested Price'[Suggested Price])
VAR _diff1=ABS(_low-max(Sales[ Sales Price ]))
VAR _diff2=ABS(_high-max(Sales[ Sales Price ]))
return if (_diff1<=_diff2,_low,_high)


Measure 2 = [Measure]-max(Sales[ Sales Price ])

 

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Ryan,

 

Thanks so much for the DAX on this, it's working pretty closely to what we'd hope to see as a result.  There are a few scenarios where I'm returning blanks for the lowest Sales Price.

 

Any recommendation for capturing $27.20 for this example below at the $12.00 Sales Price?

 

cryspezz_0-1667830099641.png

 

@cryspezz 

is that because we don't have the suggested price? 

if no suggested price, then always be 27.2?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




The suggested price at the $12.00 sales price should return $27.20 since it's the lowest suggested price point offered.  It works down to the $26 sales price, but after that it's returning a blank.

pls try 

if (isblank(suggested price), minx(values(product),suggestedprice ), max(suggested price))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I changed the result to the below and it seemed it filled in the suggested price correctly.  Thanks again for your help!

SWITCH(
    TRUE(),
    [diff1] <= [High PTR], [High PTR], [Low PTR])

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.