Forum Discussion
Amitkr174
Helper III
3 years agoCalculation based on Next Higher date along with a Condition
Hi - need your help on the below isssue.
Condition is - if Createddate>CaseCompdate,then Createddate-CaseCompdate,else NULL.
It should stop once Createddate>CaseCompdate is true, rest of the lines in the column should be blank. Output sample is attached.
Sample data with Output column
| Opp_DealR | CaseNumber | CreatedDate | Case_Comp_date | oldvalue | Newvalue | Output | |||
| DR3622342 | 2197519 | 3/8/2023 | 2/26/2023 | 02 - Prospect | 05 - Solution Definition and Validation | 10 | |||
| DR3622342 | 2197519 | 5/25/2023 | 2/26/2023 | 05 - Solution Definition and Validation | 06 - Customer Commit | 0 | |||
| DR3622342 | 2197519 | 5/26/2023 | 2/26/2023 | 06 - Customer Commit | Closed - Booked | 0 | |||
| DR3622342 | 2197519 | 5/26/2023 | 2/26/2023 | Closed - Booked | 07 - Execute to Close | 0 | |||
| DR3622342 | 2197519 | 6/1/2023 | 2/26/2023 | 07 - Execute to Close | Closed - Booked | 0 | |||
| DR3630255 | 2248914 | 3/20/2023 | 5/1/2023 | 01 - Pre Call Plan | 02 - Prospect | 0 | |||
| DR3630255 | 2248914 | 3/28/2023 | 5/1/2023 | 02 - Prospect | 03 - Opportunity Qualification | 0 | |||
| DR3630255 | 2248914 | 4/18/2023 | 5/1/2023 | 03 - Opportunity Qualification | 04 - Circle of Influence | 0 | |||
| DR3630255 | 2248914 | 5/18/2023 | 5/1/2023 | 04 - Circle of Influence | 05 - Solution Definition and Validation | 17 |
This different solution worked for me:
Output = VAR _Earliest = CALCULATE ( MIN ( 'iPOV -MicroConversion'[CreatedDate] ), ALLEXCEPT('iPOV -MicroConversion','iPOV -MicroConversion'[CaseNumber]), KEEPFILTERS ( 'iPOV -MicroConversion'[CreatedDate] > 'iPOV -MicroConversion'[Case_Comp_date] ) ) RETURN IF ( SELECTEDVALUE ( 'iPOV -MicroConversion'[CreatedDate] ) = _Earliest, DATEDIFF ( SELECTEDVALUE ( 'iPOV -MicroConversion'[Case_Comp_date] ), SELECTEDVALUE ( 'iPOV -MicroConversion'[CreatedDate] ), DAY ), 0 )
6 Replies
- rbriga
Impactful Individual
Let's try SQLBI's suggestions for RANK().
VAR SourceTable = ADDCOLUMNS ( CALCULATETABLE( ALLEXCEPT(Table, Table[Opp_DealR], Table[CaseNumber] ), KEEPFILTERS(Table[CreatedDate] > Table[Case_Comp_date]) ), "@Days", CreatedDate-Case_Comp_date ) VAR Result = RANK ( DENSE, SourceTable, ORDERBY ( [@Days], DESC, Table[CaseNumber], ASC ) ) RETURN IF( Result =1, MAX(Table[CreatedDate])- MAX(Table[Case_Comp_date]), BLANK() )May need a few adjusments, as I wasn't working on actual tables.
- Amitkr174
Helper III
- rbriga
Impactful Individual
This different solution worked for me:
Output = VAR _Earliest = CALCULATE ( MIN ( 'iPOV -MicroConversion'[CreatedDate] ), ALLEXCEPT('iPOV -MicroConversion','iPOV -MicroConversion'[CaseNumber]), KEEPFILTERS ( 'iPOV -MicroConversion'[CreatedDate] > 'iPOV -MicroConversion'[Case_Comp_date] ) ) RETURN IF ( SELECTEDVALUE ( 'iPOV -MicroConversion'[CreatedDate] ) = _Earliest, DATEDIFF ( SELECTEDVALUE ( 'iPOV -MicroConversion'[Case_Comp_date] ), SELECTEDVALUE ( 'iPOV -MicroConversion'[CreatedDate] ), DAY ), 0 )