Forum Discussion

DjZijlstra's avatar
DjZijlstra
Frequent Visitor
4 years ago
Solved

count rows with 2 tables without relationship

 

I have 2 tables.

TblUnits          
UnitIDBusinessUnitIDBuildingIDUnitStatusIDUnitCodeUnitShortNameUnitTypeIDExploitationDateFromExploitationDateToOwnerContactIDObjectID 
176122865460720317-0040.04115522-12-2021 00:0028-3-2022 00:001479362543798Not in exploitation
176112865459820317-0030.03115522-12-2021 00:00 1479352543797Has no contract
176712865385720278-5420278-54 9834-2-2022 00:00 278442581121Has an contract
176502865512720344-4320344-4398320-1-2022 00:00 858592565732Has an contract

 

and.

TblContract         
ContractIDBusinessUnitIDContractNumberCustomerIDContactIDMainUnitIDDateContractSignedDateContractFromDateContractToObjectIDActief
176232862526319574148982176718-3-2022 00:008-3-2022 00:00 25988361
1757928625237195481532721765022-2-2022 00:0022-2-2022 00:00 25860271
1732628625118192821508111761122-12-2021 22:231-1-2022 00:0025-3-2022 00:0025438900

 

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

  • DjZijlstra's avatar
    DjZijlstra
    Frequent Visitor

    Intersect was not working for me, but i have found the solution.