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
BarrySmithCONSL
New Member

Using Power Query M Formula, from within TABLE_A, count related rows in TABLE_B

From within [TRANSACTION], I need to, in the most efficient method possible, count the rows (there may be none) in [PERSON], via the field [PersonID].  I've searched, but, all the functions I've found seem to relate to the table I am working on, unless I'm completely misreading the articles.

 

TABLEs:

[TRANSACTION] > TransactionID, PersonID

[PERSON] > PersonID

 

 

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hey @BarrySmithCONSL

were the answers of any help?

Have a nice time

Jimmy

watkinnc
Super User
Super User

You could use Table.Rowcount(Table.SelectRows(TRANSACTION, each List.Contains(PERSON[PersonID], [PersonID])))


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
Jimmy801
Community Champion
Community Champion

Hello @BarrySmithCONSL 

 

try some merging and transforming like this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeJYnWglIzjLGMgyArNMgCxjMMsUyDIBs8yALFMwyxzOsgCyzJRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [TransactionID = _t, PersonID = _t]),
    PERSON = 
        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1cFGGuEgjTFIE6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [PersonID = _t])

        in
        Source,
    #"Merged Queries" = Table.NestedJoin
        (
            Source, 
            {"PersonID"}, 
            PERSON, 
            {"PersonID"}, 
            "PERSON", 
            JoinKind.LeftOuter
        ),
    Transform = Table.TransformColumns
        (
            #"Merged Queries", 
            {{"PERSON", each if Table.IsEmpty(_) then 0 else Table.RowCount(_)}}
        )
    
in
    Transform

If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun

Jimmy

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
Top Kudoed Authors