Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

USERELATIONSHIP not working?

I have the following relationships in my data model:

 

There is an active relationship between DimCalendar[Datum] and FactAppointment[Datum afspraak]. There is an inactive relationship between DimCalendar[Datum] and FactAppointment[Boeking afspraak]. 

 

When using the following DAX I get the wrong results: 

NP = 

var numberOfNewPatients = 
CALCULATE(DISTINCTCOUNT(FactAppointment[PatientID]),
FILTER(FactAppointment, FactAppointment[EarliestDateBoeking] = TRUE() && FactAppointment[EarliestDateAfspraak] = TRUE()))

var finalMeasure = 
CALCULATE(numberOfNewPatients, USERELATIONSHIP(FactAppointment[Datum boeking], DimCalendar[Datum]))

RETURN finalMeasure

 
When I manually deactivate the relationship between DimCalendar[Datum] and FactAppointment[Datum afspraak] and activate the relationship between DimCalendar[Datum] and FactAppointment[Boeking afspraak] I get the correct result. 

 

Does Anyone know what I might be doing wrong?

8 Replies

  • Thennarasu_R's avatar
    Thennarasu_R
    Responsive Resident
    CALCULATE(numberOfNewPatients, USERELATIONSHIP(DimCalendar[Datum]),FactAppointment[Datum boeking]))

    Anonymous 
    Change like this Now It will Work,
    Thanks,
    Thennarasu

    • Anonymous's avatar
      Anonymous
      Not applicable

      Does not work unfortunately.

  • Be careful when using VAR. DAX Variable is actually a constant value: once defined, it never changes. So in your case, the filter argument with USERELATIONSHIP is actually useless.  Following your thread of thought, you can try to create a intermediate measure and it shall work.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Tried an intermediate measure, but get the same result.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Has the problem be solved?

    Please consider to mark the reply as solution if it's helpful.