Forum Discussion
Subtract Row Value From Table Row Count - KM Survival Curve
Needing help with two seemingly simple issues.
First, the goal of this analysis is to peform a KM Survival Analysis. I have searched here and the articles pertaining to that analysis don't quite apply to my dataset (particularly referencing the article that Greg_Deckler wrote back in 2018.)
I'm attempting to emulate a table with the following format
Currently I have the time at event and the count of failures at each time. What I'm having trouble with first is the total pieces of equipment operating at a current time. I am attempting to accomplish this by doing a COUNTROWS() of the table I am working with and subtracting the number of failures that occured at each hour count. My table looks like the following
| EQUIP_HRS | FAILURE_AT_TIME |
| Blank | 1 |
| 0 | 1 |
| 50 | 1 |
| 100 | 1 |
| 200 | 1 |
So as mentioned I would need the output to be:
| EQUIP_HRS | FAILURE_AT_TIME | ALIVE_AT_TIME |
| Blank | 1 | 4 |
| 0 | 1 | 3 |
| 50 | 1 | 2 |
| 100 | 1 | 1 |
| 200 | 1 | 0 |
Can anyone suggest a DAX expression that will accomplish this? I have gotten ~close with the following:
- Anonymous3 years ago
Hi Ncf5031 ,
Please try this measure:
ALIVE_AT_TIME = VAR __EQUIP_HRS = MAX('FAILURES'[EQUIP_HRS]) VAR _Count_1 = CALCULATE(COUNTA('FAILURES'[EQUIP_HRS]),'FAILURES'[EQUIP_HRS]>=__EQUIP_HRS) VAR _Count_2 = COUNTBLANK('FAILURES'[EQUIP_HRS]) VAR _Count_3 = IF(ISBLANK(__EQUIP_HRS),_Count_1+_Count_2,_Count_1) VAR _Result = _Count_3 - [FAILURE_AT_TIME] RETURN _ResultBest Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
5 Replies
- AnonymousNot applicable
Hi Ncf5031 ,
It seems that the data type of the field [EQUIP_HRS] is text and a new column needs to be created to assist in sorting.
Please new a conditional column in PQ like:
Sort by column:
Then please new a measure:
ALIVE_AT_TIME = SUMX ( FILTER ( ALL ( 'FAILURES' ), 'FAILURES'[EQUIP_HRS_Sort] >= MAX ( 'FAILURES'[EQUIP_HRS_Sort] ) ), [FAILURE_AT_TIME] ) - [FAILURE_AT_TIME]Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
- Ncf5031
Advocate I
Anonymous the Equip_hrs column is not a text column, the first row is showing blank because that failure was entered into the database withthout an hour count and is therefore null.
I tried using your solution but did not come up with the expected results. In my failures table there is a total of 800 rows at present. I would expect the first row to be 795, then 794, etc.The DAX I'm using for Failures_At_Time =
CALCULATE(DISTINCTCOUNT('FAILURES'[FAILURE_ID]), ALLEXCEPT('FAILURES','FAILURES'[EQUIP_HRS]))- AnonymousNot applicable
Hi Ncf5031 ,
Please try this measure:
ALIVE_AT_TIME = VAR __EQUIP_HRS = MAX('FAILURES'[EQUIP_HRS]) VAR _Count_1 = CALCULATE(COUNTA('FAILURES'[EQUIP_HRS]),'FAILURES'[EQUIP_HRS]>=__EQUIP_HRS) VAR _Count_2 = COUNTBLANK('FAILURES'[EQUIP_HRS]) VAR _Count_3 = IF(ISBLANK(__EQUIP_HRS),_Count_1+_Count_2,_Count_1) VAR _Result = _Count_3 - [FAILURE_AT_TIME] RETURN _ResultBest Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
- AnonymousNot applicable
- Ncf5031
Advocate I
Anonymous my apologies for not updating. Your solution worked, I appreciate your assistance.