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
szub
Helper III
Helper III

Need to calculate if a unit has had a claim within one year of sale

Hello,

 

I am trying to figure out how to identify if a serial number has had a warranty claim within the first year of sale.  Below is some sample data and a measure that someone helped me with, but it is not correctly capturing all of the serial numbers.  Appreciate any assistance.

 

Sample Serial Data

Sales Serial NbrSale Date
Serial110/1/2018
Serial22/1/2018
Serial34/1/2018
Serial46/1/2018
Serial59/15/2019
Serial610/15/2019

 

Sample Claim Data:

Claim Serial NbrClaim #Claim TypeFailure Date
Serial1Claim1Warranty12/28/2018
Serial2Claim2Warranty7/1/2019
Serial3Claim3Warranty2/5/2019
Serial3Claim4Warranty8/1/2019
Serial4Claim5Startup4/30/2019

 

First Year Measure.png

 

Thank you in advance!

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

You need to change the if-statement to reflect that when the date difference is less than 366, it has a claim within a year:

had service claims in first year = 
var _curSerial = SELECTEDVALUE('Sample Serial Data'[Sales Serial Nbr])
var _salesdate = CALCULATE(SELECTEDVALUE('Sample Serial Data'[Sale Date]);'Sample Serial Data'[Sales Serial Nbr]=_curSerial)
var _firstClaim = CALCULATE(min('Sample Claim Data'[Failure Date]);'Sample Claim Data'[Claim Serial Nbr]=_curSerial)
var _dif = if(ISBLANK(_firstClaim);366;DATEDIFF(_salesdate;_firstClaim;DAY))
var _result = if(_dif<366;1;0)
return _result

 

Using this code I get the correct output for the sample data you provided in the original post 

View solution in original post

8 REPLIES 8
sturlaws
Resident Rockstar
Resident Rockstar

Hi @szub 

I think part of the reason why you are not getting the expected results is the somewhat counterintuitive behaviour of DATEDIFF:
https://docs.microsoft.com/en-gb/dax/datediff-function-dax

E.g. DATEDIFF(20191231,20200101,YEAR) return 1, not 0.

 

You can change to using DAY in your DATEDIFF-statement, and check if the difference is more than 365. 

 

Cheers,
Sturla

@sturlaws ,

 

Thank you for the feedback.  I had tried changing it to DAY and then it marked every serial number with a 1. I won't be using the measure itself in a visual, but I am putting it into a table visual to validate the results and this is what it is showing.

 

Thank you

sturlaws
Resident Rockstar
Resident Rockstar

You need to change the if-statement to reflect that when the date difference is less than 366, it has a claim within a year:

had service claims in first year = 
var _curSerial = SELECTEDVALUE('Sample Serial Data'[Sales Serial Nbr])
var _salesdate = CALCULATE(SELECTEDVALUE('Sample Serial Data'[Sale Date]);'Sample Serial Data'[Sales Serial Nbr]=_curSerial)
var _firstClaim = CALCULATE(min('Sample Claim Data'[Failure Date]);'Sample Claim Data'[Claim Serial Nbr]=_curSerial)
var _dif = if(ISBLANK(_firstClaim);366;DATEDIFF(_salesdate;_firstClaim;DAY))
var _result = if(_dif<366;1;0)
return _result

 

Using this code I get the correct output for the sample data you provided in the original post 

@sturlaws ,

 

That worked!  Thank you so much 🙂

VasTg
Memorable Member
Memorable Member

@szub 

 

Where do you display the results? as a column in the Seriel data table or in the visual. Do you have any slicer if you want to show it in the visuals?

Connect on LinkedIn

@VasTg ,

 

It will be in a column in the sales table and used to create a measure showing the percentage of units sold that had a claim in the first year of sale.

 

Thank you,

VasTg
Memorable Member
Memorable Member

@szub 

 

Try this..

Warranty_Claimed = 
VAR RELATED_RECS = RELATEDTABLE('Claim Data')
VAR MIN_FAILURE_DATE =  CALCULATE(MIN('Claim Data'[Failure Date]),FILTER(RELATED_RECS,'Claim Data'[Claim Type]="Warranty"))
VAR New_Sale_Date = DATE(YEAR('Serial Data'[Sale Date])+1,MONTH('Serial Data'[Sale Date]),DAY('Serial Data'[Sale Date]))
RETURN IF(ISBLANK(MIN_FAILURE_DATE),0,IF(MIN_FAILURE_DATE<=New_Sale_Date,1,0))

 

Based on the sample data, Here is the result.

image.png

 

If it helps, mark it as a solution

Kudos are nice too

Connect on LinkedIn

@VasTg ,

 

Thanks for the information.  When I get to the 3rd line, I am not able to select my sale date field.  It is only showing fields from the sales table that are measures.  The two tables have a relationship by the serial number as a one(sales) to many(claims). What do I need to do differently?

 

Thank you.

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.