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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Anonymous
Not applicable

How do I countrow from 1 table meeting conditions come from another table and they are not connected

Hi,

 

I have 3 tables and their relationship as pic 

hungphung_0-1616740032230.png

How do I count row in table Document when:

- Document.CaseKey = ServicePeriod.CaseKey

- Document.Date <= ServicePeriod.EndDate

- Document.Date >= ServicePeriod.StartDate

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Check the measures.

Measure = 
var start_ = CALCULATE(MAX(ServicePeriod[start]),FILTER(ServicePeriod,ServicePeriod[casekey]=SELECTEDVALUE('case'[casekey])))
var end_ = CALCULATE(MAX(ServicePeriod[end]),FILTER(ServicePeriod,ServicePeriod[casekey]=SELECTEDVALUE('case'[casekey])))
return
IF(SELECTEDVALUE(document[casekey]) in VALUES(ServicePeriod[casekey])&&SELECTEDVALUE(document[date])>=start_&&SELECTEDVALUE(document[date])<=end_,1,0)

Measure 2 = SUMX(document,[Measure])

5.PNG

 

Best Regards,

Jay

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

Check the measures.

Measure = 
var start_ = CALCULATE(MAX(ServicePeriod[start]),FILTER(ServicePeriod,ServicePeriod[casekey]=SELECTEDVALUE('case'[casekey])))
var end_ = CALCULATE(MAX(ServicePeriod[end]),FILTER(ServicePeriod,ServicePeriod[casekey]=SELECTEDVALUE('case'[casekey])))
return
IF(SELECTEDVALUE(document[casekey]) in VALUES(ServicePeriod[casekey])&&SELECTEDVALUE(document[date])>=start_&&SELECTEDVALUE(document[date])<=end_,1,0)

Measure 2 = SUMX(document,[Measure])

5.PNG

 

Best Regards,

Jay

Anonymous
Not applicable

Great.

 

Thanks a lot!

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 


countx(values(case[Case key]), filter(Document, Document[CaseKey] = max(ServicePeriod[CaseKey]) && Document[Date] <= max(ServicePeriod[EndDate]) && Document[Date] >= min(ServicePeriod[StartDate])), [Case key])

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak ,
I think the last [Case key] should not be there right? And without it, I got this warning "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value".
Cheers

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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