Help with a FILTER() expression

jamijr
New Member

Hello!

Iโ€™m trying to use a FILTER expression, but I donโ€™t understand why is it giving unexpected results.

I have two tables: Sessรฃo (with โ€œIDSessรฃoโ€ and other columns) and Agendamento (with โ€œIDAgendamentoโ€, โ€œIDSessรฃoโ€ as a reference, and other columns).

Iโ€™m setting up a workflow that will run in every update to the Agendamento table with the following condition:

COUNT(
  FILTER(Agendamento, ([IDSessรฃo] = [_THISROW_BEFORE].[IDSessรฃo]))
) = 0

I was expecting the filter to return 0 results, but it keeps returning a list with all the Agendamento in my sheet, without filtering anything.

Could anyone help me with this? Thanks in advance.

0 13 340
13 REPLIES 13

Maybe if you wish to have no condition in the condition section of the workflow, if you wish the workflow to run on any update of the said tableโ€™s row.

If you wish the workflow to run on update to a specific column in the record , you could use the method described in the article below under the title

Sending Email When a Row is Updated to Have a Specific Column Value

Please post back if you are looking for something else.

Hi!

I think I really need the condition in the workflow. I want to change the โ€œStatusโ€ of the Sessรฃo only if there are no other Agendamento referencing it.

My pain point here is the FILTER expression. I just canโ€™t understand why it keeps returning all the values in my table, ignoring my condition ([IDSessรฃo] = [_THISROW_BEFORE].[IDSessรฃo])

I also tried it with a SELECT expression SELECT(Agendamento[IDAgendamento], ([IDSessรฃo]=[_THISROW_BEFORE].[IDSessรฃo]), true), but got the same wrong result: all the values, ignoring the condition.

Thank you.

I believe you may wish to share a bit more on your requirement. Is this Sessรฃo column where you wish to change status in parent table or the child table? Do you wish to change the status when a child record is added or changed etc.? Also is your workflow essentially a data change workflow?

Hi!

The Sessรฃo table has a Status column. The Status can be either โ€œOpenโ€ or โ€œBusyโ€.
The Agendamento table has a SessรฃoID column that references to the Sessรฃo table

I already have set up a workflow that fires every time an Agendamento is created or updated. It verifies which Sessรฃo is it referencing and changes the Sessรฃo Status from โ€œOpenโ€ to โ€œBusyโ€.

What Iโ€™m trying to do now is the opposite. When an Agendamento is edited and itโ€™s SessรฃoID is changed, the app needs to change the previous Sessรฃo Status from โ€œBusyโ€ to โ€œOpenโ€. But this should only happen if there are no other Agendamento associated with that Sessรฃo.

Ideally, one Sessรฃo could have only one Agendamento, but it can happen that two or more users simultaneosly create two or more Agendamento and select the same Sessรฃo.

Thank you for more clarifications.

From the description, it appears that Agendamento is child table of Sessรฃo table. So could you please add if you are trying to change the reference column in the Agendamento table?

And if so , could you please mention any specific reason why you wish to change the reference column itself?

Hello!

Yes, the user changes the reference column in the Agendamento table. But the Status is changed at the Sessรฃo table.

Itโ€™s a scheduling app. Think about the Sessรฃo as a time slot. It has a date, time and and a staff member. The Agendamento is the appointment, it contains name, phone number, and other information about the person scheduling an appointment. Sometimes, the person needs to reschedule their appointment, thatโ€™s why we need to edit the Agendamento and change itโ€™s referenced Sessรฃo.

The app also needs to change the previous Sessรฃo Status, from Busy to Open, to make the Sessรฃo available for another person.

As per my current testing and understanding , I believe what you are looking for does not seem to be freasible. I am unsure if the previous status of ref ID can be available to update the previous parent through workflow and action combination.

Someone else may have a better insight and suggestion.

The workflow doesnโ€™t need to know what is the current Status of the previous Sessรฃo. Only if there is any Agendamento that also referes to the same Sessรฃo

I created a test workflow that sends me an e-mail on every update in Agendamento

Previous session: <<[_THISROW_BEFORE].[IDSessรฃo]>>
New session: <<[_THISROW_AFTER].[IDSessรฃo]>>

SELECT's result: <<SELECT(Agendamento[IDAgendamento], ([IDSessรฃo] = [_THISROW_BEFORE].[IDSessรฃo]))>>

This is whatโ€™s stored in Agendamento sheet:

3X_a_a_aa39dafc159bbb0ccb0ef334c8e8df451e3ec5dc.png

And this is the e-mail that the workflow sent:

Previous session: 6Ky8a5ds
New session: Nge6qOFK

SELECT's result: 19bcd910 , 2ecedf29 , ea416d4b , 0d9481b6 , 3ef8198b , 86fe2f24

As you can see on the sheet, after the update there is no Agendamento that has the previous IDSessรฃo. I expected that the SELECTโ€™s result would be empty, but it keeps returning all the IDAgendamento values.

Yes, your observation is correct that the expression returns a list. As I mentioned earlier, I am unsure about the use of [_THISROW_BEFORE] and [_THISROW_AFTER] in multirow expressions. Maybe someone else will have more insights.

I believe you need to set the previous Sessรฃo to open if the related Agendamento count is zero. And I believe that is where the challenge is of tracking the previous Sessรฃo

Alternative approach:
Anyway, I have tested the requirement with an alternative approach of reference actions and it works. However, the option is a bit long wielding. It is as follows

  1. Create two โ€œSet The values of some columns in this rowโ€ type actions on your [OpenBusy] column in the Sessรฃo table.

A) One action called say SetSessioOpen to set value to โ€œOpenโ€,
B) the other called say SetSessionBusy to โ€œBusyโ€

  1. Add a ChangeDateTime type column in Agendamento table called say [DateTimeStamp] and set the change column as โ€œIDSessรฃoโ€

  2. Create two reference actions on the Agendamento table. Action type: โ€œExecute an action on a set of rowsโ€ Reference table in both cases in this action to be set to Sessรฃo

A)One action called say SetSessioParentOpen with expression

SELECT( Sessรฃo[IDSessรฃo], AND(ISBLANK([Reverse Reference column of Agendamento table in Sessรฃo table]), (NOW()-[DateTimeStamp]<โ€œ000:00:25โ€)))
Reference action: SetSessioOpen

B) The second action called say SetSessioParentBusy with expression

SELECT( Sessรฃo[ IDSessรฃo**], AND(ISNOTBLANK([Reverse Reference column of Agendamento table in Sessรฃo table ]), (NOW()-[DateTimeStamp]<โ€œ000:00:25โ€)))
Reference action: SetSessioBusy

  1. Create a Group action on Agendamento table and have SetSessioParentOpen and SetSessioParentBusy as two actions within this group action.

  2. Set this group action as event action on Agendamento form save.

Hi! Thanks for your reply!

Before you sent it, I started to rethink my usage of the Status column and decided to go with a different approach (which now I realized itโ€™s way simpler and easier than what I was trying to do before).

I was using the Status column to just filter out all the โ€œBusyโ€ sessions (Sessรฃo) when the user is scheduling an appointment (Agendamento).

Now, I got rid of the Status column and in the appointment form, Iโ€™m using a Valid_IF expression that only selects the sessions that are not being already in use.

NOT(IN([IDSessรฃo], Agendamento[IDSessรฃo]))

This allowed me to get rid of the workflow mess that I was making. I just wish I thought about this before. Sometimes I just make things more complicated then it should be

Thank you for your patience and helping me out!

Thank you for the update. Nice to know you solved it.

Steve
Platinum 4
Platinum 4

Please post a screenshot of the workflow configuration that includes the condition expression you referenced in your original post.

@Steve
Why donโ€™t we look into the palantir instead of asking what the expression is, whatโ€™s the table schema etc.?
3X_4_6_465ea24488b4ab89f3eefbaa36f21d0654a121a7.jpeg

Top Labels in this Space