Forum Discussion
Anonymous
7 years agoNot applicable
Issue with MINX DAX Calculation
Hi, I am trying to calculate minimum start_date as IPST for a customer as below- IPST = VAR Per=SELECTEDVALUE(Patient_Population2[Person_id]) RETURN MINX(FILTER(Patient_Population2,Patient_Popu...
d_gosbell
7 years agoSuper User
The problem here is that in the call to Filter() the reference to Patient_Population2 brings in the value of the start_date as part of the filter context. So when you calcuate the first row it's filtering for the min of start_date where start_date = 11/5/2018.
One way to fix this would be to wrap the table reference in the ALL() function
IPST = VAR Per=SELECTEDVALUE(Patient_Population2[Person_id]) RETURN MINX(FILTER( ALL( Patient_Population2 ),Patient_Population2[Person_id]=Per),Patient_Population2[start_date].[Date])
A different pattern which should achieve the same effect and is slightly simpler is the following
IPST = VAR Per=SELECTEDVALUE(Patient_Population2[Person_id]) RETURN CALCULATE( MIN(Patient_Population2[start_date].[Date]), Patient_Population2[Person_id] = Per)