cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
waljalyn Frequent Visitor
Frequent Visitor

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

Accepted Solutions
KHorseman Super Contributor
Super Contributor

Re: DAX code for creating a new column - different time points

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? Please mark it as a solution.

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
KHorseman Super Contributor
Super Contributor

Re: DAX code for creating a new column - different time points

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? Please mark it as a solution.

Proud to be a Datanaut!

View solution in original post

waljalyn Frequent Visitor
Frequent Visitor

Re: DAX code for creating a new column - different time points

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

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 55 members 984 guests
Please welcome our newest community members: