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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

How to match data with data range

I have master of data range as below.

KM range
1-60
61-80
81-100

And I have transaction data as below.

TripKM
A20
B30
C70
D90

Then I would like to add column in transaction data to define KM range as below. How to set the formula?

TripKMKM range
A201-60
B301-60
C7061-80
D9081-100
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , first split the first table in power query to have additional two-column start range and end range , First duplicate the column and then split

 

https://www.tutorialgateway.org/how-to-split-columns-in-power-bi/

 

 

then add this new column in dax in table 2

maxx(filter(Table1, Table2[KM] >=Table1[Start range] && Table2[KM]<=Table1[end range]),Table1[KM range])

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in the Data Table.

=CALCULATE(VALUES(range[Range]),FILTER(range,range[Lower KM range]<=EARLIER(data[KM])&&range[Upper KM range]>=EARLIER(data[KM])))

This is how the range table is set up

Untitled.png

This is how the result looks

Untitled1.png

 


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

@Anonymous , first split the first table in power query to have additional two-column start range and end range , First duplicate the column and then split

 

https://www.tutorialgateway.org/how-to-split-columns-in-power-bi/

 

 

then add this new column in dax in table 2

maxx(filter(Table1, Table2[KM] >=Table1[Start range] && Table2[KM]<=Table1[end range]),Table1[KM range])

mhossain
Solution Sage
Solution Sage

@Anonymous 

 

1). In your 'Master Data Range' table probably you can adde two more columns, min and max, ere 1 will come in min column, 60 will go to max column.

 

2). Now you can create calculated field in your transaction data bascially and as per min max column you can build formula.

 

Hope above makes sense.

Anonymous
Not applicable

Yes I would set min and max column first. But for next step, to lookup KM range base on min and max criteria I didn't know the formula that suit

@Anonymous 

 

Formula is already provided by @amitchandak  please test and let us know if still missing something.

Anonymous
Not applicable

It is not working. How can we link between table.

Hi @Anonymous 

Based on my test, the formula seems work fine and you can refer this sample file in the below. If you have any other problems. you can share some screenshots for further dicussion.

 

KM.png

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.