Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
I'd start with adding Calendar table and AccountID table, to use following schema:
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] )
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
28 | |
12 | |
10 | |
10 | |
6 |