0

I have a problem with functions such as maxif and sumif. When I try to use any of them in my project the console returns 'Function not found: sumif/maxif; Did you mean sum/max?'

It is odd, because function countif works perfectly fine, and both of maxif and sumif are described in the BigQuery documentation, so I'm kind of worried what to do with them in order to run the code properly.

Beneath is a part of my code, any suggestions would be most welcome:

SELECT
  DISTINCT *,
  COUNTIF(status ='completed') OVER (PARTITION BY id ORDER BY created_at) cpp,  --this works
  sumif(value,status='completed') OVER (PARTITION BY id ORDER BY created_at) spp, -- this doesn't
  maxif(created_at, status = 'completed') OVER (PARTITION BY id ORDER BY created_at DESC) lastpp,
FROM
  `production.payment_transactions` 

2 Answers 2

1

Below is for BigQuery Standard SQL

#standardSQL
SELECT
  DISTINCT *,
  COUNTIF(status = 'completed') OVER (PARTITION BY id ORDER BY created_at) cpp,  --this works
  SUM(IF(status = 'completed', value, NULL)) OVER (PARTITION BY id ORDER BY created_at) spp, -- this now works
  MAX(IF(status = 'completed', value, NULL)) OVER (PARTITION BY id ORDER BY created_at DESC) lastpp, -- this now works
FROM `production.payment_transactions` 
Sign up to request clarification or add additional context in comments.

Comments

0

SUMIF() and MAXIF() are not a big query functions. Use a CASE expression:

maxif(case when status = 'completed' then created_at end) over (partition by id order by created_at desc) 

This is confusing because the functions are used in other parts of the GCP environment, particularly a component called Dataprep.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.