Filter Table before RunActions()

Hi All,

The following code will sort a table and add and adds a row with certain cells populated with data. This works great, but now I need to modify it to first filter the table to find all rows with the term “SEO” in a column before the table is sorted and the actions run to add the row. The problem is I can’t figure out how to filter the table first.

  WithName([S_DB Stats].Sort(true, [S_DB Stats].End).Last(), lMonth,
   RunActions(
    AddRow(
     [S_DB Stats],
     [S_DB Stats].LMOrgTraf, lMonth.[Organic Traffic],
     [S_DB Stats].LMOrgRev, lMonth.[Organic Revenue],
     [S_DB Stats].Start, lMonth.End+1,
     [S_DB Stats].Platform, SEO
   ),
     OpenRow([S_DB Stats].Last())
   )
 )

Any thoughts?

Hi,

It’s an idea, but maybe you can create a text field (control value) and make the table to filter on that specific control field. In your actions, you can set the control field to “SEO”.

Interesting idea and I might have to try it but it seems that I should be able to RunActions to filter the table for rows with SEO in the platform field, set the variable with WithName, add the new row and then open the row all within the script.

When I try to add in a filter to the action, it breaks the WithName.

Below is the doc. When you click the button, it sorts by the last date (as it should), but it needs to find all rows that are SEO before creating the new row so it pulls the last date for the SEO data.

Hi @Bradley_Skaggs, you were almost there.

Only needed to filter the table before sorting it.

 WithName([DB SEO].Filter(Platform=SEO).Sort(true, [DB SEO].End).Last(), lMonth,
    [...]
 )

Thank, Pablo. I just figured that out :slight_smile:

The next question is how to specify a layout for the openrow() command that is in a view of the main table…

Hi @Bradley_Skaggs,

In this part of your formula -

[S_DB Stats].Start, lMonth.End+1,

If it is certain that the dates being added will always be after those that are already in the table, then you could just do

[S_DB Stats].Start, [S_DB Stats].End.Max()+1,

… and not worry about the sorting and WithName etc.

That would be indeed a simpler solution, but the requirement is to consider only the rows where Platform=SEO so you do need to filter.

You are right that you can skip the Sort() + Last() and use Max() instead.

First you have to create a new view of the table, then create a new layout and assign it to that view.

After that, you have to pass the view as the second parameter in the OpenRow() function.

Thank you, Pablo. I ended up figuring out the view through trial and error, and ended up doing it exactly as you said :slight_smile:

OpenRow([S_DB Stats].Last(), viewOrLayout: [TikTok Stats]) 

Not sure I follow 100% what you mean about that part of my formula. Are you saying I can get rid of the withname() entirely? Or just for that line? The dates will always be added after the last date in the table.

Thanks again for your help.