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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
swisdom
Helper I
Helper I

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.

 

 Link to sample .pbix file 

 

For example:

Serial numDate submittedDate actual shipIF multiple, Days between
x234321/3/20211/25/2021NA
x854233/4/20214/2/2021NA
x234326/4/20216/17/2021141(6/4/2021-1/25/2021)
x964235/3/20215/26/2021NA
x854237/2/20217/19/202192 (7/2/2021-4/2/2021)
x234329/6/202110/2/202182 ( 9/6/2021-6/17/2021)
5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This should typically be a calculated column formula.  You may download my PBI file from here.

Hope this helps.

Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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"

swisdom_0-1644453193426.png

(I split up the code a bit just for myself so I could read it easier)

 

Any ideas why I would get that error?

Mine is a calculated column formula solution (not a measure solution).


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
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)

 

 

lbendlin_0-1644193100232.png

 

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)

swisdom_0-1644451284300.png

The ones highlighted in green are correct, but the rest I believe should be blank?

 

Any idea what is going wonky?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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