Choose Language Hide Translation Bar
Highlighted
AlexS
Level III

Data table number to Data table name with contains and Eval

Hello

The code currently works via data table number (dtlist)but what I need is the Eval to find a table based on contains then update it.

so something like Eval(contains(dtlist,("xx4") then update. if that's even possible?

 

Names Default To Here( 1 );
	
dtLIst = {};

For( i = 1, i <= N Table(), i++,
	dt = data table(i);
	insert into(dtList, dt );
);

eval(dtList[4]) << Update(
	With( Data Table( "Sales" ) ),
	Add Columns from Update table( :Name( "XX1" ) ));
	
eval(dtList[5]) << Update(
	With( Data Table( "Sales" ) ),
	Add Columns from Update table( :Name( "XX2" ) ))

many thanks

Alex is the name, Power BI/ SQL /JMP is my game
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Data table number to Data table name with contains and Eval

I think this will give you what you want

Names Default To Here( 1 );

For( i = 1, i <= N Table(), i++,
	If( Contains( Data Table( i ) << get name, "XX1" ),
		Break()
	)
);

If( i <= N Table(),
	Data Table( i ) << Update(
		With( Data Table( "Sales" ) ),
		Add Columns from Update table( :Name( "XX1" ) )
	)
);

For( i = 1, i <= N Table(), i++,
	If( Contains( Data Table( i ) << get name, "XX2" ),
		Break()
	)
);

If( i <= N Table(),
	Eval( dtList[5] ) << Update(
		With( Data Table( "Sales" ) ),
		Add Columns from Update table( :Name( "XX2" ) )
	)
);
Jim

View solution in original post

5 REPLIES 5
Highlighted
txnelson
Super User

Re: Data table number to Data table name with contains and Eval

I think this will give you what you want

Names Default To Here( 1 );

For( i = 1, i <= N Table(), i++,
	If( Contains( Data Table( i ) << get name, "XX1" ),
		Break()
	)
);

If( i <= N Table(),
	Data Table( i ) << Update(
		With( Data Table( "Sales" ) ),
		Add Columns from Update table( :Name( "XX1" ) )
	)
);

For( i = 1, i <= N Table(), i++,
	If( Contains( Data Table( i ) << get name, "XX2" ),
		Break()
	)
);

If( i <= N Table(),
	Eval( dtList[5] ) << Update(
		With( Data Table( "Sales" ) ),
		Add Columns from Update table( :Name( "XX2" ) )
	)
);
Jim

View solution in original post

Highlighted
AlexS
Level III

Re: Data table number to Data table name with contains and Eval

Perfect thank you!

Alex is the name, Power BI/ SQL /JMP is my game
Highlighted
AlexS
Level III

Re: Data table number to Data table name with contains and Eval

@txnelson 

how would I add a calculation to the table? I assume its something like

For( q = 2, q <= N Items( cols ), q++,
	For Each Row( cols[q][] = cols[q][] / :Name("xxx2") * 1000000 )

but I can't quite figure out how to put it in the code above?

 

using the code

For( i = 1, i <= N Table(), i++,
	If( Contains( Data Table( i ) << get name, "xxx" ),
		Break()
	)
);

If( i <= N Table(),
	Data Table( i ) << Update(
		With( Data Table( "Sales" ) ),
		Add Columns from Update table( :Name( "xxx2" ) )
	)
);

many thanks for your help

Alex is the name, Power BI/ SQL /JMP is my game
Highlighted
txnelson
Super User

Re: Data table number to Data table name with contains and Eval

Where does the variable "cols" come from.  Is it a List variable, containing the column name of each of the columns in the updated data table?

In your calculation, are you attempting to change the data in already existing columns, or are you attempting to create new columns in the data table?

Jim
Highlighted
AlexS
Level III

Re: Data table number to Data table name with contains and Eval

Cols is basically dt << get names then dt is current data table which I know might not be helping.

Change the data that’s there with the calculation then delete the new column added to make the calculation.
Alex is the name, Power BI/ SQL /JMP is my game