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
ndeshpande
Frequent Visitor

Checking for Partial Row Matches in the Same Table

 

Hi Folks,

I have an table called "Client_Shipments" with the following columns: [Client_name], [Send_location], [Receive_location], [Cost], [Error_rate]. I'm trying to check if for the client_name in each row, there's a match in the same table "Client_Shipments", which has the same values for [Send_Location], [Receive_Location], but does not have the same Client_name.

 

Basically, are there other clients who've sent something from the same start and end point? The [Cost] and [Error_rate] values do not need to match, since that's what I want to compare later. I created an example table below, along with the desired output in column [Match_found?].

 

Client_nameSend_locationReceive_locationCostError_rateMatch_found?
Client_ACANJ$10001%true
Client_AAZIL$30010%true
Client_AFLDE$4005%false
Client_BMACO15003%false
Client_BMOAK$5001%false
Client_BAZIL$4005%true
Client_BCANJ$12001%true

 

Any thoughts on how to make that work? Thank you in advance.

1 ACCEPTED SOLUTION
Smauro
Solution Sage
Solution Sage

Hi @ndeshpande 

You could add it as a new column:

 

Match_Found_Col =
VAR cl = [Client_name]
VAR sl = [Send_location]
VAR rl = [Receive_location]
VAR c =
    COUNTROWS (
        CALCULATETABLE (
            VALUES ( ClientOrders ),
            FILTER (
                ALL ( ClientOrders ),
                [Send_location] = sl
                    && [Receive_location] = rl
                    && [Client_name] <> cl
            )
        )
    ) + 0
RETURN
    IF ( c > 0, TRUE (), FALSE () )

 


Or as a measure:

 

Match_Found_Mes =
VAR cl =
    FIRSTNONBLANK ( ClientOrders[Client_name], 1 )
VAR sl =
    SELECTEDVALUE ( ClientOrders[Send_location], "123" )
VAR rl =
    SELECTEDVALUE ( ClientOrders[Receive_location], "123" )
VAR c =
    COUNTROWS (
        CALCULATETABLE (
            VALUES ( ClientOrders ),
            FILTER (
                ALL ( ClientOrders ),
                [Send_location] = sl
                    && [Receive_location] = rl
                    && [Client_name] <> cl
            )
        )
    ) + 0
RETURN
    IF ( c > 0, TRUE (), FALSE () )

 

 

Cheers


Edit: Ah, sorry @parry2k , I hadn't seen your answer.




Feel free to connect with me:
LinkedIn

View solution in original post

4 REPLIES 4
Smauro
Solution Sage
Solution Sage

Hi @ndeshpande 

You could add it as a new column:

 

Match_Found_Col =
VAR cl = [Client_name]
VAR sl = [Send_location]
VAR rl = [Receive_location]
VAR c =
    COUNTROWS (
        CALCULATETABLE (
            VALUES ( ClientOrders ),
            FILTER (
                ALL ( ClientOrders ),
                [Send_location] = sl
                    && [Receive_location] = rl
                    && [Client_name] <> cl
            )
        )
    ) + 0
RETURN
    IF ( c > 0, TRUE (), FALSE () )

 


Or as a measure:

 

Match_Found_Mes =
VAR cl =
    FIRSTNONBLANK ( ClientOrders[Client_name], 1 )
VAR sl =
    SELECTEDVALUE ( ClientOrders[Send_location], "123" )
VAR rl =
    SELECTEDVALUE ( ClientOrders[Receive_location], "123" )
VAR c =
    COUNTROWS (
        CALCULATETABLE (
            VALUES ( ClientOrders ),
            FILTER (
                ALL ( ClientOrders ),
                [Send_location] = sl
                    && [Receive_location] = rl
                    && [Client_name] <> cl
            )
        )
    ) + 0
RETURN
    IF ( c > 0, TRUE (), FALSE () )

 

 

Cheers


Edit: Ah, sorry @parry2k , I hadn't seen your answer.




Feel free to connect with me:
LinkedIn

@Smauro 

This is perfect, thank you!

parry2k
Super User
Super User

@ndeshpande you can try following method

 

Add new column and measure and measure will return true/false

 

Receive and Send Column = 'Table'[Receive_location] & 'Table'[Send_location]


Is Exist Measure = 
VAR __current = VALUES ( 'Table'[Receive and Send Column] )
VAR __client = SELECTEDVALUE ( 'Table'[Client_name] )
VAR __other = CALCULATETABLE ( VALUES ( 'Table'[Receive and Send Column] ), ALL ( 'Table'[Receive and Send Column] ), 'Table'[Client_name] <> __client )
VAR __isExist = CALCULATE ( COUNTROWS ( 'Table' ), INTERSECT ( __other, __current ) ) + 0
RETURN
IF ( __isExist = 0, "False", "True" )

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks for the quick response, I was thinking I'll probably need to convert the measure to a column. However the combining the relevant separate column values into a single colum was a great idea because it will simplify my searches later on. 

 

Thank you!

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