The issue you're facing with the date function in your XPath expression is likely due to the way dates are being formatted and compared. In CommCare, date calculations can be tricky, especially when using functions like today() and date(). Here's a revised approach to help you achieve your goals:
Count the total number of participants in a selected village:
count(instance('casedb')/casedb/case[
village = #form/village and @status = 'open'
])
Count how many participants have treatment = 'yes' for today and the previous day:
Instead of using format-date, you can use the date() function directly with today() to calculate the date for today and yesterday. However, ensure that the submission_date is stored in a comparable format (e.g., yyyy-mm-dd). Here's a revised expression:
count(instance('casedb')/casedb/case[
village = #form/village and
treatment = 'yes' and @status = 'open' and
(
submission_date = today() or
submission_date = date(today() - 1)
)
])
Make sure that submission_date is stored in a format that matches the output of today() and date() functions. If the date format is different, you might need to adjust the format or use additional functions to ensure compatibility.