Forum Discussion
Calculation IF a value appears in earlier rows
I have a set of data including RMAs with various dates. I would like to create a measure which calculates if a particular Serial Number has been returned multiple times, and IF it does, to calculate the date difference between the most recent Actual Ship Date and the current Date Submitted.
For example:
| Serial num | Date submitted | Date actual ship | IF multiple, Days between |
| x23432 | 1/3/2021 | 1/25/2021 | NA |
| x85423 | 3/4/2021 | 4/2/2021 | NA |
| x23432 | 6/4/2021 | 6/17/2021 | 141(6/4/2021-1/25/2021) |
| x96423 | 5/3/2021 | 5/26/2021 | NA |
| x85423 | 7/2/2021 | 7/19/2021 | 92 (7/2/2021-4/2/2021) |
| x23432 | 9/6/2021 | 10/2/2021 | 82 ( 9/6/2021-6/17/2021) |
5 Replies
- lbendlin
Super User
Thank you for providing the sample data
If multiple, Days between = var ds=SELECTEDVALUE(RMA[Date Submitted]) var pasd = CALCULATE(max(RMA[ACTUAL_SHIP_DATE]),ALLEXCEPT(RMA,RMA[Serial Num]),RMA[ACTUAL_SHIP_DATE]<ds) return DATEDIFF(pasd,ds,DAY)- swisdom
Helper I
Thank you for your response!
So I can see that this is working on your pbix file, but for some reason when I apply it to my own file, it does something weird and gives values for entries that shouldn't have them (see below)
The ones highlighted in green are correct, but the rest I believe should be blank?
Any idea what is going wonky?
- Ashish_Mathur
Super User
Hi,
This should typically be a calculated column formula. You may download my PBI file from here.
Hope this helps.
- swisdom
Helper I
Hello thank you for your response!
So your method looks great, however when I try to apply it to my actual dataset (not the test dataset) I get this error: "Circular dependency was detected"
(I split up the code a bit just for myself so I could read it easier)
Any ideas why I would get that error?
- Ashish_Mathur
Super User
Mine is a calculated column formula solution (not a measure solution).