Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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 Variable 2 ONLY IF the ID has a value of 1 for Variable 1 at Time point 0, otherwise Variable 3 will remain blank at all time points for that ID.

So I would want my resulting table to look like this:

Capture.PNG
Does anyone know what the DAX code would be to create this column? 

Thanks

1 ACCEPTED SOLUTION
KHorseman
Community Champion
Community Champion

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.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
KHorseman
Community Champion
Community Champion

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.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Yes - this is exactly what I needed. Thank you so much!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.