Forum Discussion
Anonymous
7 years agoNot applicable
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...
- 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 )
AlB
Community Champion
7 years agoHi Anonymous
Interesting solution. I'm curious, why do you need the CALCULATETABLE in VAR a? Wouldn't you get exactly the same table without it? i.e.:
VAR a =
FILTER ( ALL ( 'Session' ), 'Session'[UserID] = EARLIER ( 'Session'[UserID] ) )
in fact, the ALL() is superfluous since no filter context is present:
VAR a =
FILTER ( 'Session', 'Session'[UserID] = EARLIER ( 'Session'[UserID] ) )
Anonymous
7 years agoNot applicable
AlB - You're absolutely correct - thank you for catching that!