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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

need DAX to emulate Subselect to find parent records without child records (self-referencing)

The requirement is to find records that have no children...the application in this case is to find incoming emails (emailid) in CRM that have not been replied to...in other words, where *the emialid does not appear in any other record's parentactivityid field* in the same table. 

In SQL the query would look something like..

select emailid from emails e
where
   (select count(parentactivityid)
   from emails p
   where e.emailid = p.parentactivityid and e.createdon<p.createdon
   )
< 1

To be clear, email responses list the original emailid in the parentactivityid field. Therefore, emails that have not been responded to will not have their emailid entered in any parentactivityid record, therefore the subselect looks for count = 0.

Please excuse the long explanation.

any help is appreciated

2 REPLIES 2
Greg_Deckler
Super User
Super User

Probably something along the lines of:

 

Measure 2 = 
VAR __table = ALL('Table4')
VAR __table1 = ADDCOLUMNS(__table,"__count",COUNTX(FILTER(__table,[parentactivityid]=EARLIER(Table4[emailid]) && [createdon]>EARLIER([createdon])),[emailid]))
VAR __table2 = FILTER(__table1,[__count]<1)
RETURN
CONCATENATEX(__table2,[emailid],",")

See Page 3, Table 4.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I'll be working your through suggestion, along with Microsoft's suggestion to use PATH (to determine parent-child relationships), along with a web example I found showing a similar application using the CALCULATETABLE expression. 

I'll post findings as soon as I get to the bottom of this. Thx for your suggestions. 

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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.