Forum Discussion
count rows with 2 tables without relationship
I have 2 tables.
| TblUnits | |||||||||||
| UnitID | BusinessUnitID | BuildingID | UnitStatusID | UnitCode | UnitShortName | UnitTypeID | ExploitationDateFrom | ExploitationDateTo | OwnerContactID | ObjectID | |
| 17612 | 286 | 5460 | 7 | 20317-004 | 0.04 | 1155 | 22-12-2021 00:00 | 28-3-2022 00:00 | 147936 | 2543798 | Not in exploitation |
| 17611 | 286 | 5459 | 8 | 20317-003 | 0.03 | 1155 | 22-12-2021 00:00 | 147935 | 2543797 | Has no contract | |
| 17671 | 286 | 5385 | 7 | 20278-54 | 20278-54 | 983 | 4-2-2022 00:00 | 27844 | 2581121 | Has an contract | |
| 17650 | 286 | 5512 | 7 | 20344-43 | 20344-43 | 983 | 20-1-2022 00:00 | 85859 | 2565732 | Has an contract |
and.
| TblContract | ||||||||||
| ContractID | BusinessUnitID | ContractNumber | CustomerID | ContactID | MainUnitID | DateContractSigned | DateContractFrom | DateContractTo | ObjectID | Actief |
| 17623 | 286 | 25263 | 19574 | 148982 | 17671 | 8-3-2022 00:00 | 8-3-2022 00:00 | 2598836 | 1 | |
| 17579 | 286 | 25237 | 19548 | 153272 | 17650 | 22-2-2022 00:00 | 22-2-2022 00:00 | 2586027 | 1 | |
| 17326 | 286 | 25118 | 19282 | 150811 | 17611 | 22-12-2021 22:23 | 1-1-2022 00:00 | 25-3-2022 00:00 | 2543890 | 0 |
there is a non-actief relationship between MainUnitID and UNITID.
I use for to count active contracts = CALCULATE( COUNTROWS(tblContract),
IF(AND(tblContract[DateContractFrom]<=max(dates[date]),OR(tblContract[DateContractTo] >= max(dates[date]), tblContract[DateContractTo]= 0)), 1,0))
And for active unit count i use = CALCULATE(COUNTROWS(tblUnit), IF(AND(tblUnit[ExploitationDateFrom]<=max(dates[date]),OR(tblUnit[ExploitationDateTo] >= max(dates[date]), tblUnit[ExploitationDateTo]= 0)), 1,0))
But now i need to count the free units of both tables on a max(dates[date]). That is a unit who is active with no contract. In this example is that 1 unit. nr. 17611.
And i would like to count the units wiht an contract. In this example is that 2 with numbers 17671 and 17650.
Can anyone help me with a solution?
Thanks!!
Intersect was not working for me, but i have found the solution.
2 Replies
- DjZijlstraFrequent Visitor
Intersect was not working for me, but i have found the solution.
- lbendlin
Super User
Read about the DAX functions EXCEPT() and INTERSECT()