Atualizar campo em outra tabela usando BOT

Olรก pessoal, boa tarde

Gostaria de saber se podem me socorrer em um problema que estou tendo no meu BOT.

Eu criei um BOT que quando recebe a atualizaรงรฃo de um determinado campo na tabela pai ele deve replicar um valor na tabela Y.

Acontece assim:
1. Quando meu vendedor finaliza um pedido da tabela "hPedidos" (Cabeรงalho dos pedidos);

2. O Bot verifica se o campo STATUS รฉ igual a finalizado e entรฃo inicia o processo;

2.1 O primeiro processo o Bot envia um e-mail comunicando o gerente de รกrea que existe um pedido novo no sistema para dar andamento;

2.2 o Segundo passo do BOT e atualizar alguns campos da tabela de "Clientes", sendo eles:

Data da ultima compra = today()

รšltimo valor comprado = Aqui que mora o problema, pois pra eu pegar o valor do pedido eu preciso olhar na tabela "hPedidos", existe um relacionamento entre elas pelo campo ID_CLIENTE, os pedidos sรฃo sequenciais.

Estou tentando usar essa fรณrmula para pegar esse valor:

MAXROW("hPedidos",TOTAL,[ID_CLIENTE]=[_THISROW].[ID_CLIENTE])

Porรฉm, dรก o seguinte erro na execuรงรฃo do BOT:

Error encountered in step with name [Atualiza Cadastro do Cliente]: 
Error:
Perform DataAction 'Atualiza ficha cliente (pedido=Finalizado)' failed because Row having key '02828446000134' in table 'Clientes' containing value '60ec99cd' in field 'VAL ULT COMPRA' cannot be converted to type 'Price'.

Retirei o campo acima e quando rodo o BOT dรก certo apenas o campo Data da รบltima compra, pois estou pegando na fรณrumla basicamente.

 

Como posso resolver isso?

Solved Solved
0 3 339
1 ACCEPTED SOLUTION

You misunderstood the purpose of MAXROW(). Anyway, you don't need it. The correct expression to use is:

ANY( SELECT(hPedidos[Total],
  AND([Date] = TODAY(), [ID_Cliente] = [_ThisRow].[ID_CLIENTE])
))

Assuming a client could only make one order per day.  

View solution in original post

3 REPLIES 3

You misunderstood the purpose of MAXROW(). Anyway, you don't need it. The correct expression to use is:

ANY( SELECT(hPedidos[Total],
  AND([Date] = TODAY(), [ID_Cliente] = [_ThisRow].[ID_CLIENTE])
))

Assuming a client could only make one order per day.  

Hi Mr @Joseph_Seddik ,[

Thanks for your helphand. 

But can you clarify when shoud I use ANY() or MAXROW()? 

sorry for bothering you

Not at all, this is a very good question.

MAXROW() will give you only row keys, more specifically the key of the row containing the highest value of a certain column. So when you use:

MAXROW("hPedidos",TOTAL,[ID_CLIENTE]=[_THISROW].[ID_CLIENTE])

the expression will not give you the highest value of the TOTAL column. Instead, you'll get the key of the row that contains this highest value. If your highest value in this column is 10.000, MAXROW() will not give you 10.000, but will tell you this: the hPedido that contains the highest total value is hPedido number xyz. 

If instead you want to retrieve values from a certain column, a part from the key, based on certain conditions, here you should use SELECT(), which will give you all the corresponding values in the selected column, in the rows where the condition was fulfilled. SELECT() will give you a list, even if the result contains only one value, it will still be a list containing one element. ANY() is used to retrieve any single value from the list, and in case we have single-value list, ANY() will retrieve this value removing the list data type. 

You'll enjoy reading this excellent post:

FAQ: FILTER(), LOOKUP(), MAXROW(), MINROW(), REF_R... - Google Cloud Community  

Top Labels in this Space