Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calculated Column's formula is based on a value in a column

Sorry if the subject is really vague, but what I just want to know if this is possible in Power BI. Let's say I have this table: Country Created Date Assigned Date Completed Date Closed Date ...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Anonymous 

    You can't use the formula in columns, but you can use switch function like  

    In addition to  

     

    Date Difference = 
    VAR _DateDifferenceCalucation = CALCULATE(MAX('Calculation'[Date Difference Calculation]),FILTER('Calculation','Calculation'[Country]=EARLIER('Table'[Country])))
    VAR _Closed_Created =
        DATEDIFF ( 'Table'[Created Date], 'Table'[Closed Date], DAY )
    VAR _Closed_Assigned =
        DATEDIFF ( 'Table'[Assigned Date], 'Table'[Closed Date], DAY )
    VAR _Closed_Completed =
        DATEDIFF ( 'Table'[Completed Date], 'Table'[Closed Date], DAY )
    VAR _Completed_Assigned =
        DATEDIFF ( 'Table'[Assigned Date], 'Table'[Completed Date], DAY )
    VAR __Completed_Created =
        DATEDIFF ( 'Table'[Created Date], 'Table'[Completed Date], DAY )
    RETURN
        SWITCH (
            _DateDifferenceCalucation,
            "Closed Date - Created Date", _Closed_Created,
            "Completed Date - Created Date", __Completed_Created,
            "Closed Date - Assigned Date", _Closed_Assigned,
            "Completed Date - Assigned Date", _Completed_Assigned,
            _Closed_Completed
        )

     

    You can download the pbix file from this link: Calculated Column's formula is based on a value in a column

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.