Get last value of a column where another cell value equals to

I am building an spreadsheet to follow up income (which has two types : Cash and Cheque).

Date | Type | Amount

I can get sum of “Cash Total” or “Cheque Totat” with the following functions:

=SUMPRODUCT(B4:B504="Cash",C4:C504)
=SUMPRODUCT(B4:B504="Cheque",C4:C504)

and, get the last date entry on date column:

=IF(ISNA(LOOKUP(1E+099,A4:A504)),"-",LOOKUP(1E+099,A4:A504))

What I need to achieve, "Getting last date entry where type equals to Cash or Cheque.

Thanks for any help.

Please see attached sample, two ways, enter as array formula or with SUMPRODUCT() to force the array.

Find_Max_Row_with_conditions.ods