Create On-Demand data table to store marked data points using C#?

Hello, I am trying to figure out if it is possible to create an On-Demand data table using C# (I am planning to create a CustomTool). What I am trying to do is basically programmatically add a new On-Demand data table that is set up to store only what the user marks on a visualisation (limited by Marking). Below is my attempt at creating that table but it doesn't seem to work, can somebody more experienced taka e look at it? 


protected override void ExecuteCore(AnalysisApplication context)
	var d = context.Document;
	var dt = d.Data.Tables["Wells"];
	var ds = new DataTableDataSource(dt);
	var dataFlowBuilder = new DataFlowBuilder(ds, null);
	var newTable = dataFlowBuilder.Build();

	d.Data.Tables.Add("NewTableName", newTable);

(1) Answer