Forum Discussion

DjZijlstra's avatar
DjZijlstra
Frequent Visitor
4 years ago
Solved

Count rows with different tables

Hi there,   I have 2 tables:   and      there is an non-active relationship between MainUnitID and UnitID. I use for the count of active contracts: CALCULATE( COUNTROWS(tblContrac...
  • v-kkf-msft's avatar
    v-kkf-msft
    4 years ago

    Hi DjZijlstra ,

     

    This is because I did not de-duplicate the TbIContract[MainUnitID] column, please try the modified measure:

     

    count the units with contract = 
    VAR tab_contract =
        FILTER (
            TbIContract,
            AND (
                TbIContract[DateContractFrom] <= MAX ( 'dates'[date] ),
                OR (
                    TbIContract[DateContractTo] >= MAX ( 'dates'[date] ),
                    TbIContract[DateContractTo] = 0
                )
            )
        )
    VAR tab_units =
        FILTER (
            TbIUnits,
            AND (
                TbIUnits[ExploitationDateForm] <= MAX ( dates[date] ),
                OR (
                    TbIUnits[ExploitationDateTo] >= MAX ( dates[date] ),
                    TbIUnits[ExploitationDateTo] = 0
                )
            )
        )
    RETURN
        CALCULATE (
            DISTINCTCOUNT(TbIContract[MainUnitID]),
            tab_contract,
            tab_units,
            USERELATIONSHIP ( TbIUnits[UnitID], TbIContract[MainUnitID] )
        )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.