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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

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

Anonymous
Not applicable

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

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.