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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
JSiebrecht
Resolver I
Resolver I

Count Records Without Match in Related Table

I have 2 related tables:
'Contract' with a looooong list of contracts conducted
'Contract_UdF' a table accounting for some user defined fields that could not be added to the general data structure.

Records in the UdF table are linked by the foreign key [CONTRACT_ID].
Particular items are identified by [NAME] (e.g. "Inst Type"). [VALUE] then contains the actual data.

JSiebrecht_0-1638873455360.png


I need a measure with the overall COUNT of records in 'Contract' that do NOT have a corresponding record in 'Contract_Udf'

with [NAME] = "Inst Type".

 

Example:

I have 4 contracts in the 'Contract' table. They have corresponding records in the related table 'Contract_UdF'. 
[CONTRACT_ID] 100000001, 100000003 and 100000004 have a record wiht [NAME] = "Inst Type".
But 100000002 does NOT.

 

The value of the measure shall be 1.

 

JSiebrecht_2-1638874557644.png

 

THANKS FOR YOU HELP!

Best regards,
Jan

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@JSiebrecht , Try a measure like

countx(filter(summarize(Contract_udf, contract[contract], "_1", countrows(filter(Contract_udf, Contract_udf[Name] = "Inst Type"))+0), [_1]=0), [contract])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

Hi @amitchandak 
thanks for the prompt response.

With the small typological adjustment (in pink below) it works fine! Many thanks.

Checking the results maually I found a glitch in my thinking though.
How do I need to adjust the measure if Inot only want to count the non-existing records
but also the existing records with [NAME] = "Inst Type" but a blank [VALUE]?I 

I suppose simply add the additional filter (in green) like so, isn't it?!?

 

CountContracts_NULL_Inst_Type =
countx(filter(summarize('Contract Udf', 'Contract Udf'[CONTRACT_ID], "_1", countrows(filter('Contract Udf', 'Contract Udf'[NAME] = "Inst Type" && 'Contract Udf'[VALUE] <> BLANK()))+0), [_1]=0), [CONTRACT_ID])

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@JSiebrecht , Try a measure like

countx(filter(summarize(Contract_udf, contract[contract], "_1", countrows(filter(Contract_udf, Contract_udf[Name] = "Inst Type"))+0), [_1]=0), [contract])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak 
thanks for the prompt response.

With the small typological adjustment (in pink below) it works fine! Many thanks.

Checking the results maually I found a glitch in my thinking though.
How do I need to adjust the measure if Inot only want to count the non-existing records
but also the existing records with [NAME] = "Inst Type" but a blank [VALUE]?I 

I suppose simply add the additional filter (in green) like so, isn't it?!?

 

CountContracts_NULL_Inst_Type =
countx(filter(summarize('Contract Udf', 'Contract Udf'[CONTRACT_ID], "_1", countrows(filter('Contract Udf', 'Contract Udf'[NAME] = "Inst Type" && 'Contract Udf'[VALUE] <> BLANK()))+0), [_1]=0), [CONTRACT_ID])

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.