Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hola Comunidad, necesito su ayuda, estoy aplicando un código con set analysis, con el objetivo de escoger una fecha y luego seleccionar el mismo mes de hace un año atras, para esto estoy usando el siguiente código: count({$<event.montFDate={"$(=monthname(max(event.montFDateP),-12))"}>}distinct(order_id))
Ahora necesito aplicar una misma lógica, pero lograr obtener el total del mes de hace un año atras y los dos meses anteriores, es decir, si escojo ahorita el mes de enero del 2024, esta lógica logre tener la suma de enero/2023, diciembre/2022 y noviembre del 2022
Espero que mi duda quede clara y poder tener ayuda de ustedes.
Saludos.
Please try this:
count({$<event.montFDate={">=$(=addmonths(max(event.montFDate),-14))<=$(=addmonths(max(event.montFDate),-12))"}>}distinct order_id)
Hola @pravinboniface
Probe, pero me da valor 0
Can you please share the format of event.montFDate? I think there may be a date format mismatch with what I tried. I tested with data looking as follows
load * inline [
event.montFDate,order_id
1/1/2023,1
2/1/2023,2
];
@melperso21 If you have a date in the format 'MMM YYYY', the approach will not work even if we cast the dates to be in that format.
For example, we could code something like this where we format the date as 'MMM YYYY'
count({$<event.montFDate={">=$(=date(addmonths(max(date#(event.montFDate,'MMM YYYY')),-14),'MMM YYYY'))<=$(=date(addmonths(max(date#(event.montFDate,'MMM YYYY')),-12),'MMM YYYY'))"}>}distinct order_id)
But this will resolve to
count({<event.montFDate={">=Dec 2021<=Feb 2022"}>}distinct order_id)
This will not work because the greater than and less than will treat the date in alphanumerical order.
The best way to do this is to first convert event.montFDate to a date using date(date#([event.montFDate],'MMM YYYY'),'YYYYMMDD')
Then apply the original expression.
count({$<event.montFDate={">=$(=addmonths(max(event.montFDate),-14))<=$(=addmonths(max(event.montFDate),-12))"}>}distinct order_id)
I hope this helps