recordsortedlist

Hi,

My objective is to compute for totals inside a while loop and do a one trip insert pass to the database at the end (outside the loop). I’m using a recordsortedlist because there would be more scenarios - tables to looked up/get values/update into before inserting it in a table (i just didn’t include it here) and I’m new with recordsortedlist. Appreciate any help.

rsl= new RecordSortedList(tablenum(insertToTable));
rsl.sortOrder(fieldnum(insertToTable,line));

while (sourceTable)
order by sourceTable.line
{
insertToTable.clear();
insertToTable.TotalAmt += souceTable.Amount;
rsl.ins(insertToTable);
}

rsl.insertDatabase();
rsl = null;

Thank you…

Not sure what you are really doing here. But the above logic to happen, you need to have a local variable, increment it with sourceTable.Amount and then assign it to TotalAmt;

Regarding RecordSortedList class, this will definetly help you http://msdn.microsoft.com/en-us/library/aa862829(v=ax.50).aspx

Hi,

I presume you are working in DAX 2009.

The pseudo-code in your post looks OK. What exact help are you looking for?

Two things…this does an insert…are you sure you don’t want to do an update? And if you do want to do an insert, it looks like you’re assigning a static value “souceTable.Amount” over and over. WHY you’re doing this…doesn’t make sense, but if that’s what you’re doing, you would be better off with insert_recordset.

If you’re just trying to figure out how to use RecordSortedList, then it looks like the basic syntax is right…but it doesn’t look logical in any way.