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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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])

 

 

Share with Power BI Enthusiasts: 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.