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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rashidanwar
Helper III
Helper III

Lookup range of values based on 2 columns and select for the lowest value in the group

Hi

I have 2 tables as follow. I want to lookup and bring the contact_compay name (output is in blue) in tables one based on order_group_id and the lowest order_id in the relevant order_group. 
For example for order_group_id 1, there are 3 {1, 2, 3} order_ids. But we need to lookup the value for the lowest order_id, that is 1 and the value would be the ABC
Table 1

order_group_idOrder_idLookup Values (Contact Company)
11ABC
12ABC
13ABC
24JKL
25JKL
26JKL

Table 2

order_group_idorder_idorderline_idcontact_company
111ABC
112ABC
121DEF
122DEF
123DEF
131GHI
241JKL
242JKL
253LMN


Thank you so much for all your help.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Contact company CC =
VAR currentordergroup = Table1[order_group_id]
VAR _filterTable2 =
    FILTER ( Table2, Table2[order_group_id] = currentordergroup )
VAR _minorderid =
    MINX ( _filterTable2, Table2[order_id] )
VAR _minorderidtable =
    SUMMARIZE (
        FILTER (
            Table2,
            Table2[order_group_id] = currentordergroup
                && Table2[order_id] = _minorderid
        ),
        Table2[contact_company]
    )
RETURN
    IF ( COUNTROWS ( _minorderidtable ) = 1, _minorderidtable )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
rashidanwar
Helper III
Helper III

Thank you so much @Jihwan_Kim  and @amitchandak for your help.

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Contact company CC =
VAR currentordergroup = Table1[order_group_id]
VAR _filterTable2 =
    FILTER ( Table2, Table2[order_group_id] = currentordergroup )
VAR _minorderid =
    MINX ( _filterTable2, Table2[order_id] )
VAR _minorderidtable =
    SUMMARIZE (
        FILTER (
            Table2,
            Table2[order_group_id] = currentordergroup
                && Table2[order_id] = _minorderid
        ),
        Table2[contact_company]
    )
RETURN
    IF ( COUNTROWS ( _minorderidtable ) = 1, _minorderidtable )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@rashidanwar , a new column

 

new column =
var _1 = minx(allselected(table1), table1[order_group_id] = earlier(Table[order_group_id])), [Order_id])
return
maxx(filter(Table2, Table2[order_group_id] = Table1[order_group_id] && Table2[Order_id]=_1), [contact_company])

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.