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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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