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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
anthony_dobson
Frequent Visitor

Match 2 data sources by latest keyid

Hey I have 2 tables both containing PCName, KeyID, KeyDateTime for 2 different data backup sources A and B, where the PCNames are related many:many. Multiple KeyIDs can exist for a PCName and the KeyIDs may or may not exist in both sources.

 

I want to query the the latest KeyID by KeyDateTime for the PCName exists in both data sources that is Compliant, else report if table A or B has a newer KeyID that only exists in either table.

 

Any ideas on how to tackle this?

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @anthony_dobson ,

According to your description, I create a sample.

TableA:

vyanjiangmsft_0-1685353599670.png

TableB:

vyanjiangmsft_1-1685353632167.png

Here's my solution, create a measure:

 

Latest_keyID =
MAXX (
    FILTER (
        'TableA',
        'TableA'[KeyID]
            = MAXX (
                FILTER (
                    ALL ( 'TableB' ),
                    'TableB'[PCName] = MAX ( TableA[PCName] )
                        && 'TableB'[KeyDateTime]
                            = MAXX (
                                FILTER ( ALL ( 'TableB' ), 'TableB'[PCName] = MAX ( TableA[PCName] ) ),
                                'TableB'[KeyDateTime]
                            )
                ),
                'TableB'[KeyID]
            )
    ),
    'TableA'[KeyID]
)

 

Get the latest KeyID by KeyDateTime for the PCName exists in both data sources:

vyanjiangmsft_2-1685354133856.png

If you want to count the number of PCName meet the above condition, create a measure:

 

Measure =
CALCULATE (
    DISTINCTCOUNT ( 'TableA'[PCName] ),
    FILTER (
        ALL ( 'TableA' ),
        'TableA'[KeyID]
            = MAXX (
                FILTER (
                    ALL ( 'TableB' ),
                    'TableB'[PCName] = EARLIER ( TableA[PCName] )
                        && 'TableB'[KeyDateTime]
                            = MAXX (
                                FILTER ( ALL ( 'TableB' ), 'TableB'[PCName] = EARLIER ( TableA[PCName] ) ),
                                'TableB'[KeyDateTime]
                            )
                ),
                'TableB'[KeyID]
            )
    )
)

 

Get the correct result:

vyanjiangmsft_3-1685354494721.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @anthony_dobson ,

According to your description, I create a sample.

TableA:

vyanjiangmsft_0-1685353599670.png

TableB:

vyanjiangmsft_1-1685353632167.png

Here's my solution, create a measure:

 

Latest_keyID =
MAXX (
    FILTER (
        'TableA',
        'TableA'[KeyID]
            = MAXX (
                FILTER (
                    ALL ( 'TableB' ),
                    'TableB'[PCName] = MAX ( TableA[PCName] )
                        && 'TableB'[KeyDateTime]
                            = MAXX (
                                FILTER ( ALL ( 'TableB' ), 'TableB'[PCName] = MAX ( TableA[PCName] ) ),
                                'TableB'[KeyDateTime]
                            )
                ),
                'TableB'[KeyID]
            )
    ),
    'TableA'[KeyID]
)

 

Get the latest KeyID by KeyDateTime for the PCName exists in both data sources:

vyanjiangmsft_2-1685354133856.png

If you want to count the number of PCName meet the above condition, create a measure:

 

Measure =
CALCULATE (
    DISTINCTCOUNT ( 'TableA'[PCName] ),
    FILTER (
        ALL ( 'TableA' ),
        'TableA'[KeyID]
            = MAXX (
                FILTER (
                    ALL ( 'TableB' ),
                    'TableB'[PCName] = EARLIER ( TableA[PCName] )
                        && 'TableB'[KeyDateTime]
                            = MAXX (
                                FILTER ( ALL ( 'TableB' ), 'TableB'[PCName] = EARLIER ( TableA[PCName] ) ),
                                'TableB'[KeyDateTime]
                            )
                ),
                'TableB'[KeyID]
            )
    )
)

 

Get the correct result:

vyanjiangmsft_3-1685354494721.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors