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
newtonvr
Regular Visitor

how to compare same values in the same column

Hi there!

 

Please see attached screenshot to clarify my needs: 

newtonvr_0-1619087157769.png

 

I'm trying to find the time elapsed between the dateperformed column for each patient, but don't want the time elasped between the dates if the patientIDS aren't the same because that data is irrelevant to me and messes up my visuals. My goal for a new calculated column is, if the patientIDs are the same, return the value in the timelapsedFilterNeg column, and if they are not, return 0. My trouble is I am not sure how to write the formula that says "if the previous value in this column is the same as the next value...".

I am aware that the patientID string is a mixture of numbers and digits, and I have no problem adding a column of only integers to represent the patientID if needed. 

 

Please let me know if I can clarify the issue in any way, thanks!

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @newtonvr ,

 

Use the index column to create a new index column for each patientID.

new_index = RANKX(FILTER('Table','Table'[id]=EARLIER('Table'[id])),'Table'[index],,ASC)

1.PNG

Then you could compare the value depends on the new index column.

Column = 
var earlier_value = CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[id]=EARLIER('Table'[id])&&'Table'[new_index]=EARLIER('Table'[new_index])-1))
return
IF(ISBLANK(earlier_value),0,'Table'[value]-earlier_value)

2.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @newtonvr ,

 

Use the index column to create a new index column for each patientID.

new_index = RANKX(FILTER('Table','Table'[id]=EARLIER('Table'[id])),'Table'[index],,ASC)

1.PNG

Then you could compare the value depends on the new index column.

Column = 
var earlier_value = CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[id]=EARLIER('Table'[id])&&'Table'[new_index]=EARLIER('Table'[new_index])-1))
return
IF(ISBLANK(earlier_value),0,'Table'[value]-earlier_value)

2.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@newtonvr , based on what I got, Try a new column like

datediff( maxx(filter(Table, [patientID] = earlier([patientID]) && [Date] < earlier([Date])),[Date]),[Date], day)

Following your advice, I created a new column with the following formula: 

Column = datediff( maxx(filter(assessment_activity_data, [patientID] = earlier([patientID]) && [dateperformed] < earlier([dateperformed])),[dateperformed]),[dateperformed], day)
 
However, the following photo shows the results:
newtonvr_0-1619095568660.png

 

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.