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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Get Counts in one table with related records in another table filtered by dates

I have two tables A and B as shown below. The AccountID in A has a relationship with the AccountID in B. 

 

A

AccountID CmpName AccFlag SysStartTime
A1 Test1 1 1/1/2020
A2 Test2 0 1/2/2020
A3 Test3 1 1/2/2020


B

ContactId AccountID ConFlag SysStartTime
C1 A1 1 1/1/2020
C2 A1 1 1/1/2020
C3 A1 0 1/1/2020
C4 A2 1 1/2/2020


I want to get the count of records in A that have 3 related records in B in a measure. The record A1 in A has 3 records with A1 in B. So the count returned should be 1. I want to filter the results based on the sysStartTime of A and B as well. For example, I want to get the count of records in A that have 3 related records in B as of 1/1/2010. I tried many things but I can't get the DAX for this. Please advice. 

 

 

1 REPLY 1
Stachu
Community Champion
Community Champion

I'd start with adding Calendar table and AccountID table, to use following schema:
Capture.PNG

M code for AccountID based on A & B:

let
    Source = #table({"AccountID"},{{List.Distinct(List.Combine({A[AccountID],B[AccountID]}))}}),
    #"Expanded AccountID" = Table.ExpandListColumn(Source, "AccountID")
in
    #"Expanded AccountID"

then this measure will work:

Measure =
VAR __B_WithCount =
    ADDCOLUMNS ( 'AccountID', "Count", COUNTROWS ( RELATEDTABLE ( 'B' ) ) )
VAR __B_Filtered =
    FILTER ( __B_WithCount, [Count] = 3 )
RETURN
    COUNTX ( __B_Filtered, [AccountID] )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.