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 )
Anonymous
7 years agoNot applicable
Anonymous - You could do something like this:
Flag =
VAR a =
CALCULATETABLE(
'Session',
FILTER ( ALL ( 'Session' ), 'Session'[UserID] = EARLIER ( 'Session'[UserID] ) )
)
VAR b = MAXX(a,[UsedFeature])
VAR c = MINX(a,[UsedFeature])
RETURN
SWITCH (
b & c,
"NoNo", 0,
"YesYes", 1,
2
)or this:
Flag =
VAR a =
CALCULATE (
MIN ( 'Session'[UsedFeature] ),
FILTER ( ALL ( 'Session' ), 'Session'[UserID] = EARLIER ( 'Session'[UserID] ) )
)
VAR b =
CALCULATE (
MAX ( 'Session'[UsedFeature] ),
FILTER ( ALL ( 'Session' ), 'Session'[UserID] = EARLIER ( 'Session'[UserID] ) )
)
RETURN
SWITCH (
a & b,
"NoNo", 0,
"YesYes", 1,
2
)Cheers!
Nathan