Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Create a calculated column based on another value in the same table

Hello.   I have a table with 3 columns (SessionID, UserID, UsedFeature) and I want to create a calculated column with a flag that is 0 if a user has never used the feature in all of his sessions, 1...
  • AlB's avatar
    7 years ago

    Hi  Anonymous ,

    Try this:

     

    NewColumn =
    VAR Num_Yes_ =
        CALCULATE (
            COUNT ( Table1[UsedFeature] ),
            ALLEXCEPT ( Table1, Table1[UserID] ),
            Table1[UsedFeature] = "Yes"
        )
    VAR Num_No_ =
        CALCULATE (
            COUNT ( Table1[UsedFeature] ),
            ALLEXCEPT ( Table1, Table1[UserID] ),
            Table1[UsedFeature] = "No"
        )
    VAR Num_Total_ = Num_Yes_ + Num_No_
    RETURN
        SWITCH ( Num_Total_, Num_No_, 0, Num_Yes_, 1, 2 )