Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DAX code for creating a new column - different time points

I am trying to create a new column (Variable 3) based off of the ID, Time point, Variable 1, and Variable 2 in the table below. I want to create a new column (Variable 3) which copies the value of Va...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Let me see if I understand correctly. If there is a row for this ID where Time point = 0 and Variable 1 = 1, always copy Variable 2 for that ID. If not leave it blank. Right?

     

    Variable 3 = VAR tp1 = COUNTROWS(
    	FILTER(
    		ALL(TableName),
    		TableName[ID] = EARLIER(TableName[ID])
    		&& TableName[Time point] = 0
    		&& TableName[Variable 1] = 1
    	)
    )
    RETURN IF(
    	tp1 <> 0,
    	TableName[Variable 2],
    	BLANK()
    )

    You could do it without the VAR/RETURN by just cramming all that COUNTROWS stuff in where I reference tp1 below, but this is easier to read IMO.