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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ramusoc
Regular Visitor

Check if a value is included in an interval of another table

Hello everyone,

 

I want to know a value from Table 1 in which interval (Table 2) it exists and get the category from Table 2, as the example below: 

Table 1 

Client |  Sales

1        |  100

2        |   50

3        |   25

4        |   2

 

Table 2:

min   |   max |  Category

0       |   20    |   A

21     |   60    |   B

61     |   100  |   C

 

The output should be :

Client |  Sales   | Category

1        |  100      | A

2        |   50       | B

3        |   25       | B

4        |   2         | C

 

Could you please help me on that issue.

Thanks in advance.

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Not sure if you want a column or measure expression, but here is a column one.

 

Category =
VAR thissales = Table1[Sales]
RETURN
    MINX (
        FILTER ( Table2, Table2[min] <= thissales && Table2[max] >= thissales ),
        Table2[Category]
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Employee
Employee

Not sure if you want a column or measure expression, but here is a column one.

 

Category =
VAR thissales = Table1[Sales]
RETURN
    MINX (
        FILTER ( Table2, Table2[min] <= thissales && Table2[max] >= thissales ),
        Table2[Category]
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hey, 

It worked. Thanks a lot !!

lbendlin
Super User
Super User

In DAX you would use GENERATESERIES and INTERSECT

 

In Power Query you would use List.Generate and List.Contains

 

What's your preference?

Hey Ibendlin,

 

Thank you for your interest.

 

I'd prefer DAX, but how am i going to use generateseries and intersect?

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors