0

I am writing code to select the maximum value from a column that does not equal two other large values. The maximum will always be the 3rd largest value. The two largest values are place holders, (int) in year month format 999912, and 999901.

I have tried using Max and Filter together with no luck.

val maxSurvey = s.max("SurveyMonth").filter(survey("SurveyMonth") =!= "999912" && survey("SurveyMonth") =!= "999901")

I expect the current result to be 201902.

1
  • try s.filter($"SurveyMonth" != ""999912" && $"SurveyMonth") != "999901").max($"SurveyMonth") Commented Apr 22, 2019 at 19:56

1 Answer 1

1

You need select the max, but your code is wrong in the filter too, if you need Max, why you compare SurveyMonth with a String?

After changes your code will look like:

val maxSurvey = s.filter('SurveyMonth =!= 999912 && 'SurveyMonth =!= 999901).select(max('SurveyMonth))
Sign up to request clarification or add additional context in comments.

1 Comment

you can use 'column_name when you need refer a column

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.