cancel
Showing results for
Did you mean:
Highlighted
Frequent Visitor

## How to find the nearest match and value against that

Hi Everyone,

I am new to the Power BI and Stuck in a situation. I need to find the price of the pack nearest to the filter, if exact pack size is not available.

I have attached the sample data in which I need to find the minimum price from all the countries. If two records are available for single country we need to find the nearest one on the basis of pack size and than basis the full list we need to find the minimum price.

I have mentioned the criteria below.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support

## Re: How to find the nearest match and value against that

Hi @Abhik

``````Flag_1 =
var a =
CALCULATE(MIN(Data[Abs_size]),ALLEXCEPT(Data,Data[Country]))
return
IF(Data[Abs_size]=a&&Data[Flag]=1,1,0)``````
``````Measure 2 =
IF(SELECTEDVALUE('HO Status'[HO Status])="Include HO",1,IF(SELECTEDVALUE(Data[HS Status])<>"HO",1,0))``````
``Measure 3 = CALCULATE(MIN(Data[Unit_Price]),FILTER(Data,Data[Flag_1]=1&&[Measure 2]=1))*10``

Pbix attached.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
5 REPLIES 5
Super User IV

## Re: How to find the nearest match and value against that

---------------------------------------

Putting square pegs in round holes since 1972.

##### I have a NEW book! DAX Cookbook from Packt
Over 120 DAX Recipes!

Proud to be a Datanaut!

Community Support

## Re: How to find the nearest match and value against that

Hi @Abhik

you might consider creating pbix file that will contain some sample data (remove the confidential info), upload the pbix to onedrive or dropbox and share the link to the file. Please do not forget to describe the expected results based on this sample data.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Frequent Visitor

## Re: How to find the nearest match and value against that

Hi Greg,

Best Regards,

Abhik

Community Support

## Re: How to find the nearest match and value against that

Hi @Abhik

``````Flag_1 =
var a =
CALCULATE(MIN(Data[Abs_size]),ALLEXCEPT(Data,Data[Country]))
return
IF(Data[Abs_size]=a&&Data[Flag]=1,1,0)``````
``````Measure 2 =
IF(SELECTEDVALUE('HO Status'[HO Status])="Include HO",1,IF(SELECTEDVALUE(Data[HS Status])<>"HO",1,0))``````
``Measure 3 = CALCULATE(MIN(Data[Unit_Price]),FILTER(Data,Data[Flag_1]=1&&[Measure 2]=1))*10``

Pbix attached.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Frequent Visitor

## Re: How to find the nearest match and value against that

Hi Team,

Thank you soo much for your support on this. This is exactly what I am looking for.

I have one last question, how i can calculate average of 3 lowest price insted of minimum price is attached pbix file?

Abhik

Announcements

#### Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

#### MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

#### ‘Better Together’ Integration Forum Launch

We've launched a how-to forum where you can learn about how Power BI integrates with other Power Platform products.

Top Solution Authors
Top Kudoed Authors