Trailing 12 month distinct counts for each month in the dataset

Hi,

I am trying to add a visual to show the last 12 month distinct counts for each month in the dataset. Windowsum is not working for me, as it is summing up the distinct counts for the last 12 months. I want to get the distinct count on the last 12 months data, rather than summing the distinct counts for each month in the last 12 months. It is related to the below post and author mentioned that they are able to implement the workaround. Can someone help me on how to achieve it?

Here’s a calculation to get your dates grouped to the last twelve months.

truncDate(‘YYYY’,addDateTime(-dateDiff(truncDate(‘YYYY’,{arrival_timestamp}),now()),‘DD’,{arrival_timestamp}))

This would be to get the distinct Count if it’s this year.
avg(distinctCountOver(ifelse({last tweleve months}=addDateTime(-1,‘YYYY’,now()),{session_id},NULL),[{last tweleve months}],PRE_AGG))

Let me know if that works for you.