Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kdesai
Frequent Visitor

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_Population2[Person_id]=Per),Patient_Population2[start_date].[Date])

 

I am using a table visual.
Patient_Population2 table lists all the start_dates for a customer.

 

But what I am getting is a value similar to start_date column for IPST, see screen shot below

Capture.PNG


I am expecting the output to be this

Capture1.PNG

1 REPLY 1
d_gosbell
Super User
Super 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)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.