2
votes

I have two tables as indicated below. The first is a list of dates, the second a list of contracts with their contract start and end dates. The tables are not related since there are two date realtionships. I need to give a summary of how many contracts started and ended on each day. This works fine using a calcualted column, however, when I try and slice on Type or Contract customer, the results in the Date table's calculated columns do not apply, even though ALLSELECTED is applied. How can I get the slicers to filter the rows returned to the to calculated column so that the number of contracts are calculated accordingly.

Calculated column:

StartedContracts = COUNTROWS(FILTER(ALLSELECTED(Contracts), Contracts[StartDate] = DateData[Date]))

Reproduction PBIX here

Sample layout

1

1 Answers

2
votes

To get this displaying correctly, an easy way is to go ahead and set up the relationships between the tables. You'll have an active relationship and an inactive relationship, something like this with an active relationship to [StartDate] and an inactive relationship to [EndDate]: multiple relationships set between Contracts and DateData tables

Having done this, defining the measures is simplicity itself!

StartedContracts = COUNTROWS(Contracts)
EndedContracts = CALCULATE(COUNTROWS(Contracts), USERELATIONSHIP(Contracts[EndDate], DateData[Date])

Since the active relationship is to the Contracts[StartDate] column, you don't need to specify any additional filters for StartedContracts.

When calculating EndedContracts you just need to add USERELATIONSHIP() to the CALCULATE() function to tell it to use the inactive relationship which was previously defined to the Contracts[EndDate] column.

Slicers on other columns work as expected.