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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
sanrajbhar
Frequent Visitor

Join table based on value from second table if value is withing range of those column values

Any guide how one can join table based on value from table1 less than or greate than / between two value from table2. it looks fairly doable in sql. but i have csv table how can I achive similar in power bi Enviroment ? Below is snpashot for more information.

 

Capture.PNG

1 ACCEPTED SOLUTION

Hi @sanrajbhar ,

 

First create an index column in table B;

Then create a calculated column as below:

 

Column = 
var _start=CALCULATE(MAX('Table B'[Column 2]),FILTER('Table B','Table B'[Column 1]="Start chainage"))
var _index=CALCULATE(MAX('Table B'[Index]),FILTER('Table B','Table B'[Column 2]=_start))
var _end=CALCULATE(MAX('Table B'[Column 2]),FILTER('Table B','Table B'[Index]=_index+1))
var _chain=CALCULATE(MAX('Table A'[Column2]),FILTER('Table A','Table A'[Column1]="Chainage"))
Return
IF('Table A'[Column1]="Chainage",
IF(_chain>=_start&&_chain<=_end,CALCULATE(MAX('Table B'[Column 2]),FILTER('Table B','Table B'[Index]=_index-1)),BLANK()))

 

 

And you will see:

v-kelly-msft_0-1607560932336.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

5 REPLIES 5
PaulDBrown
Community Champion
Community Champion

@sanrajbhar 

You will need to set up your tables by columns first (pivot them in Power Query). 
Then you can use a measure to "filter" IDs by the criteria you need.

can you share actual sample data (with more IDs) instead of an image?

please read this thread:

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






thanks for reply. here IDs are not important. I need to match if chainage is between chainage_start and chainage_end and do the joins.

Hi  @sanrajbhar ,

 

First add an index column in both 2 tables;

Then create a new table as below:

Union Table = UNION('Table A','Table B')

Then create 2 measures,and you will see:

Screenshot 2020-12-09 135242.png

For details, pls see attached.

 

 
 
 

 

Best Regards,
Kelly

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

Probably I am not able to put Question correctly .I have updated Question (screenshot) what I wished to do. thanks

Hi @sanrajbhar ,

 

First create an index column in table B;

Then create a calculated column as below:

 

Column = 
var _start=CALCULATE(MAX('Table B'[Column 2]),FILTER('Table B','Table B'[Column 1]="Start chainage"))
var _index=CALCULATE(MAX('Table B'[Index]),FILTER('Table B','Table B'[Column 2]=_start))
var _end=CALCULATE(MAX('Table B'[Column 2]),FILTER('Table B','Table B'[Index]=_index+1))
var _chain=CALCULATE(MAX('Table A'[Column2]),FILTER('Table A','Table A'[Column1]="Chainage"))
Return
IF('Table A'[Column1]="Chainage",
IF(_chain>=_start&&_chain<=_end,CALCULATE(MAX('Table B'[Column 2]),FILTER('Table B','Table B'[Index]=_index-1)),BLANK()))

 

 

And you will see:

v-kelly-msft_0-1607560932336.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.