cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
achakilam Frequent Visitor
Frequent Visitor

join two tables and find min after doing group by

Hi all,

 

I want to join two tables `Data` and `Priority`  and create a new column in the `Data` table which is Data.Reason_Final

join tables on Data. Reason = Priority.Reason and Data.Reason_Final = min(Priority.PriorityOrder) based on group by Data.ID

Could you please help me figure out how to do this in PowerBI?

 

Data:

IDReason
1ABC
1DEF
3DEF
3GHI
5GHI
5ABC
5DEF

 

Priority:

ReasonPriorityOrder
ABC1
DEF2
GHI3

 

Final Result:

IDReasonReason_Final
1ABCABC
1DEFABC
3DEFDEF
3GHIDEF
5GHIABC
5ABCABC
5DEFABC

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: join two tables and find min after doing group by

@achakilam 

 

Please try this calculated column

 

Column =
MINX (
    TOPN (
        1,
        FILTER ( Data, [ID] = EARLIER ( [ID] ) ),
        RELATED ( Priority[PriorityOrder] ), ASC
    ),
    [Reason]
)
Try my new Power BI game Cross the River

View solution in original post

3 REPLIES 3
Super User
Super User

Re: join two tables and find min after doing group by

@achakilam 

 

Please try this calculated column

 

Column =
MINX (
    TOPN (
        1,
        FILTER ( Data, [ID] = EARLIER ( [ID] ) ),
        RELATED ( Priority[PriorityOrder] ), ASC
    ),
    [Reason]
)
Try my new Power BI game Cross the River

View solution in original post

Super User
Super User

Re: join two tables and find min after doing group by

Hi @achakilam 

If there's no relationship between the tables Data and Priority, you can create a new calculated column:

NewColumn =
VAR IDReasons_ =
    CALCULATETABLE ( DISTINCT ( Data[Reason] ); ALLEXCEPT ( Data; Data[ID] ) )
VAR AuxTable_ =
    CALCULATETABLE ( Priority; TREATAS ( IDReasons_; Priority[Reason] ) )
RETURN
    CALCULATE (
        DISTINCT ( Priority[Reason] );
        TOPN ( 1; AuxTable_; [PriorityOrder]; ASC )
    )

 

achakilam Frequent Visitor
Frequent Visitor

Re: join two tables and find min after doing group by

Thanks a lot!

Helpful resources

Announcements
New Ranks and Rank Icons in 2020

New Ranks and Rank Icons in 2020

Read the announcement for more information!

New Kudos Given Badges Coming

New Kudos Given Badges Coming

We're rolling out new Kudos Given badges. Find out how many Kudos you've given.

November 2019 Community Highlights

November 2019 Community Highlights

Get an overview of the events and great community content from November.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)