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
Greg_Deckler
Super User
Super User

Kaplan Meier Survival Curves

@Buzzshot43 posted a question on KM Survival Curves here:

https://community.powerbi.com/t5/Desktop/KM-Survival-Curve-in-Power-BI/m-p/326809#M145836

 

The post refers to the following Tableau article:

https://www.linkedin.com/pulse/survival-curves-tableau-hr-data-chris-short/

 

So, figured I'd give it a shot and have gotten part of the way there but was hoping the community could help me finish this off.

 

I am using the dataset from the Tableau article referenced above and am trying to recreate this using pure Power BI (no R). I imported the data as HRData. The data looks like:

 

ID,Name,Hire Date,Termination Date,Status,Department

1,Inez Laurie,4/23/2010,9/2/2015,Inactive,HR

2,Yasuko Scruton,1/20/2010,,Active,Sales

...

 

So, in the dataset, I created the following custom columns:

Years = IF([Status]="Active",DATEDIFF(HRData[Hire Date],TODAY(),YEAR),DATEDIFF(HRData[Hire Date],HRData[Termination Date],YEAR))

Event = IF(HRData[Status] = "Inactive",1,0)

Count = 1

 

I created a Calendar table using 

 

Calendar = CALENDARAUTO(12)

Which I tied to Termination Date (relationship)

 

I created a measure to give me a running total for Count:

 

Count running total in Date = 
CALCULATE(
	SUM('HRData'[Count]),
	FILTER(
		ALLSELECTED('Calendar'[Date]),
		ISONORAFTER('Calendar'[Date], MAX('Calendar'[Date]), DESC)
	)
)

I created a measure for d_i:

 

d_i = SUM(HRData[Event])

I created a measure for n_i

 

n_i = COUNTROWS(HRData) + CALCULATE(COUNTROWS(HRData),ALL(HRData)) - [Count running total in Date]

This is where things get a little messy. The formula for KM goes something like:

 

(Previous Value of KM) * (1-d_i/n_i)

 

So, what I did was create three measures like this:

 

KM1 = 1-[d_i]/[n_i]

KM-1 = CALCULATE([KM1],DATEADD('Calendar'[Date],-1,DAY))

KM = [KM-1]*[KM1]

The thought here was that I could have a continuous line chart by [Date] in Calendar and calculate KM1 for that date, KM1 for the previous date (KM-1) and then use those to calculate KM.

 

But, I'm not really getting what I expected and was wondering if someone could take a look and see if they can get this to work or have a better way.

 

 

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
1 ACCEPTED SOLUTION

Full solution posted here:

https://www.linkedin.com/pulse/kaplan-meier-survival-curves-power-bi-greg-deckler-microsoft-mvp-

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

10 REPLIES 10

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.