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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Danielecc
Helper II
Helper II

How to search a group of rows in other table

Hi everyone, 

I would like to know how we can search a group of rows from table1 in table 2.

 

The Group to search is table2, group by "AREA", and that group must be searched in table1, , the example is:

 

Busca Grupo.PNG

 

O.Mena is not in "result expected" because he got only 1 row of the group and 1 row in the other group, to be in result expected you have to match all rows of the group.

 

The tables are:

 

Table1:

USERCountryOrganizationItemValue
D.CelisChile1Company_G7Quantity4
D.CelisChile1Company_G9ProductPRD13
J.SmithChile2Company_G7ProductPRD02
R. PerezChile2Company_G9ProductPRD15
R. PerezChile2Company_G5UnitMeter
R. PerezChile3Company_G8Quantity2
R. PerezChile3Company_G5ProductPRD01
R. PerezChile4Company_G5UnitMeter
C.LezmaPeru1Company_H2Quantity4
C.LezmaPeru1Company_I3LongLA2
C.LezmaPeru2Company_J4ProductART23
C.LezmaPeru2Company_H2Quantity2
O. MenaPeru3Company_H2Quantity2
O. MenaPeru3Company_H2ProductART12
O. MenaPeru4Company_L3Quantity3
O. MenaPeru4Company_L4Quantity2

 

 

Table2:

CityAreaOrganizationItemValue
SantiagoL.CondesCompany_G7Quantity2
SantiagoÑuñoaCompany_G7ProductPRD02
SantiagoVitacuraCompany_G8Quantity2
SantiagoVitacuraCompany_G9ProductPRD15
LimaChorrillosCompany_H2Quantity2
LimaChorrillosCompany_I3LongLA2
LimaChorrillosCompany_J4ProductART23
LimaSan IsidroCompany_H2Quantity2
LimaSan IsidroCompany_H2ProductART10
LimaLinceCompany_L3Quantity2
LimaLinceCompany_L4Quantity2

 

Thanks a lot and best regards...

 

 

1 ACCEPTED SOLUTION

@Danielecc  can be achieved with a measure like this

_Value = 
VAR _city =
    MINX (
        ADDCOLUMNS (
            Table1,
            "X",
                MINX (
                    FILTER (
                        Table2,
                        Table2[Organization] = EARLIER ( Table1[Organization] )
                            && Table2[Item] = EARLIER ( Table1[Item] )
                            && Table2[Value] = EARLIER ( Table1[Value] )
                    ),
                    Table2[City]
                )
        ),
        [X]
    )
VAR _area =
    MINX (
        ADDCOLUMNS (
            Table1,
            "X",
                MINX (
                    FILTER (
                        Table2,
                        Table2[Organization] = EARLIER ( Table1[Organization] )
                            && Table2[Item] = EARLIER ( Table1[Item] )
                            && Table2[Value] = EARLIER ( Table1[Value] )
                    ),
                    Table2[Area]
                )
        ),
        [X]
    )
VAR _count1 =
    COUNTX (
        FILTER ( Table2, Table2[City] = _city && Table2[Area] = _area ),
        Table2[City]
    )
VAR _count2 =
    CALCULATE (
        COUNTX (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    Table1,
                    "@city",
                        MINX (
                            FILTER (
                                Table2,
                                Table2[Organization] = EARLIER ( Table1[Organization] )
                                    && Table2[Item] = EARLIER ( Table1[Item] )
                                    && Table2[Value] = EARLIER ( Table1[Value] )
                            ),
                            Table2[City]
                        )
                ),
                "@Area",
                    MINX (
                        FILTER (
                            Table2,
                            Table2[Organization] = EARLIER ( Table1[Organization] )
                                && Table2[Item] = EARLIER ( Table1[Item] )
                                && Table2[Value] = EARLIER ( Table1[Value] )
                        ),
                        Table2[Area]
                    )
            ),
            [@city]
        ),
        ALLEXCEPT ( Table1, Table1[USER] )
    )
RETURN
    IF (
        _count1 - _count2 = 0,
        MINX (
            ADDCOLUMNS (
                Table1,
                "X",
                    MINX (
                        FILTER (
                            Table2,
                            Table2[Organization] = EARLIER ( Table1[Organization] )
                                && Table2[Item] = EARLIER ( Table1[Item] )
                                && Table2[Value] = EARLIER ( Table1[Value] )
                        ),
                        Table2[Value]
                    )
            ),
            [X]
        )
    )

 

smpa01_0-1637350227034.png

pbix is attached

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

7 REPLIES 7
smpa01
Super User
Super User

@Danielecc  you can create a measure like this

City =
MAXX (
    ADDCOLUMNS (
        Table1,
        "X",
            MAXX (
                FILTER (
                    Table2,
                    Table2[Organization] = EARLIER ( Table1[Organization] )
                        && Table2[Item] = EARLIER ( Table1[Item] )
                        && Table2[Value] = EARLIER ( Table1[Value] )
                ),
                Table2[City]
            )
    ),
    [X]
)

 

which will give you the following

smpa01_0-1637331866921.png

But what did you mean by - O.Mena is not in "result expected" because he got only 1 row of the group and 1 row in the other group, to be in result expected you have to match all rows of the group

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01 , this imagen show why O.Mena is not on result expected table:

 

OMENA.PNG

 

Thanks again for your help...

 

Wooooooow @smpa01 Something like that is what I need.

About your question:

O. Mena not must be in the table of result expected, because the Group "San Isidro" from "Lima" has 2 rows and O.Mena get match only with one of that 2 rows.

The same case with "Lince" from "Lima".

 

Only J.Smith, R.Perez and C.Lezma match all rows group by "Area" on table2. (like show the arrows).

 

Thanks again @smpa01 that was very close.

@Danielecc  can be achieved with a measure like this

_Value = 
VAR _city =
    MINX (
        ADDCOLUMNS (
            Table1,
            "X",
                MINX (
                    FILTER (
                        Table2,
                        Table2[Organization] = EARLIER ( Table1[Organization] )
                            && Table2[Item] = EARLIER ( Table1[Item] )
                            && Table2[Value] = EARLIER ( Table1[Value] )
                    ),
                    Table2[City]
                )
        ),
        [X]
    )
VAR _area =
    MINX (
        ADDCOLUMNS (
            Table1,
            "X",
                MINX (
                    FILTER (
                        Table2,
                        Table2[Organization] = EARLIER ( Table1[Organization] )
                            && Table2[Item] = EARLIER ( Table1[Item] )
                            && Table2[Value] = EARLIER ( Table1[Value] )
                    ),
                    Table2[Area]
                )
        ),
        [X]
    )
VAR _count1 =
    COUNTX (
        FILTER ( Table2, Table2[City] = _city && Table2[Area] = _area ),
        Table2[City]
    )
VAR _count2 =
    CALCULATE (
        COUNTX (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    Table1,
                    "@city",
                        MINX (
                            FILTER (
                                Table2,
                                Table2[Organization] = EARLIER ( Table1[Organization] )
                                    && Table2[Item] = EARLIER ( Table1[Item] )
                                    && Table2[Value] = EARLIER ( Table1[Value] )
                            ),
                            Table2[City]
                        )
                ),
                "@Area",
                    MINX (
                        FILTER (
                            Table2,
                            Table2[Organization] = EARLIER ( Table1[Organization] )
                                && Table2[Item] = EARLIER ( Table1[Item] )
                                && Table2[Value] = EARLIER ( Table1[Value] )
                        ),
                        Table2[Area]
                    )
            ),
            [@city]
        ),
        ALLEXCEPT ( Table1, Table1[USER] )
    )
RETURN
    IF (
        _count1 - _count2 = 0,
        MINX (
            ADDCOLUMNS (
                Table1,
                "X",
                    MINX (
                        FILTER (
                            Table2,
                            Table2[Organization] = EARLIER ( Table1[Organization] )
                                && Table2[Item] = EARLIER ( Table1[Item] )
                                && Table2[Value] = EARLIER ( Table1[Value] )
                        ),
                        Table2[Value]
                    )
            ),
            [X]
        )
    )

 

smpa01_0-1637350227034.png

pbix is attached

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01  OMG man....

 

It is not enough to accept as a solution, I also had to respond and thank you for this giant code, the time you used to respond to the post. And I swear I didn't see ANYTHING similar on any website as a solution, I almost give up.

 

Thank you a lot!!!

Greg_Deckler
Community Champion
Community Champion

@Danielecc Sure, you can use LOOKUPVALUE or MAXX(FILTER(...),...)



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler  I am searching about LOOKUPVALUE and MAXX(FILTER(...),...) to see if this solve the example.

Best regards...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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