Sort by two date fields in the ORDER BY Expression box.

Duncan Koza asked on March 9, 2020 20:53

I have a bunch of News articles that I am listing down a page with a repeater. Some of the news articles have a DocumentPublishFrom date and others do not.

I'd like to order the articles by DocumentPublishFrom, but if there isn't a DocumentPublishFrom, then I'd like to use DocumentCreatedWhen.

I am using the following code in the ORDER BY expression field (clicking on the black arrow) but it seem to not be working properly. Am I doing something wrong?

{% If (DocumentPublishFrom<DocumentCreatedWhen) { "DocumentCreatedWhen DESC" } else {"DocumentPublishFrom DESC"} #%}

Correct Answer

Peter Mogilnitski answered on March 9, 2020 22:41

COALESCE(DocumentPublishFrom ,DocumentCreatedWhen) DESC

0 votesVote for this answer Unmark Correct answer

Recent Answers


Duncan Koza answered on March 9, 2020 21:07

I think I found the answer, at least it appear to be working now.

DocumentPublishFrom DESC, DocumentCreatedWhen DESC

I guess a macro wasn't needed.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on March 10, 2020 19:12

Thanks Peter. Looks like my way didn't work, but yours worked perfectly. Thanks.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.