Forum Discussion

Hayleysea's avatar
Hayleysea
Icon for Resolver II rankResolver II
6 years ago
Solved

Calculated column based on whether value is available against ID

Hi There,   I have a table with project ID's, stages and dates. Stages range from 1 to 5 but not all project ID's have a stage 5 entry. In the case they don't have a Stage 5 entry I need to use Sta...
  • Zubair_Muhammad's avatar
    6 years ago

    Hayleysea 

     

    Try this calculated column

     

    Column =
    VAR Stage5_present =
        NOT (
            ISEMPTY (
                CALCULATETABLE (
                    VALUES ( TableName[Stage] ),
                    ALLEXCEPT ( TableName, TableName[Project ID] ),
                    TableName[Stage] = 5
                )
            )
        )
    VAR Value_I_Want =
        IF (
            Stage5_present,
            CALCULATE (
                MAX ( TableName[Date] ),
                ALLEXCEPT ( TableName, TableName[Project ID] ),
                TableName[Stage] = 5
            ),
            EDATE (
                CALCULATE (
                    MAX ( TableName[Date] ),
                    ALLEXCEPT ( TableName, TableName[Project ID] ),
                    TableName[Stage] = 4
                ),
                1
            )
        )
    RETURN
        IF ( [Stage] = 4, Value_I_Want )