LAC calculation on a visual

I have created 2 LAC calculated fields,
d_bucket:

count({outb_final_quantity_requested},[{prod_product_id},{site_site_id},{order_date}])/
distinct_count({LAG String},[{prod_product_id},{site_site_id},{order_date}])

d_period:

dateDiff(min({order_date}),max({order_date}),"DD")

Then did some calculations on fields to generate average demand and categorize it into bins

ADI:

{d_bucket}/{d_period}

ADI bins:

ifelse(
{ADI}>0 AND {ADI}<=5, '0-5 days',
{ADI}>5 AND {ADI}<=10, '5-10 days',
{ADI}>10 AND {ADI}<=15, '10-15 days',
{ADI}>15 AND {ADI}<=20, '15-20 days',
'>20 days'
)

Now, when i put ADI bin to the visual in x axis, i get lac calculation on visual error.
I believe this is because of the LAC fields i generated.

Is there a way to generate same result for d_bucket by using LAC-W calculation?

(Note: the same result for d_bucket is done in sql by giving the following query:

select count(*) as d_bucket,p_id from
 (select count(*),day(order_date),p_id 
  from order_line 
  group by day(order_date),month(order_date),year(order_date),p_id) 
group by p_id;

Hope this helps)

Hello @mamilone !

Could you try the following:

d_bucket:

count({outb_final_quantity_requested}) 
/ 
distinctCountOver({LAG String}, [prod_product_id, site_site_id, order_date])

d_period:

dateDiff(minOver(min({order_date}), [prod_product_id, site_site_id]), maxOver(max({order_date}) ,[prod_product_id, site_site_id]), 'DD')

Let me know if that works or if you hit any errors.

Thanks for the response @duncan ,

d_period is working like you suggested, Thank You!!

I updated my calculated field d_bucket as:
d_bucket_1:

count({outb_final_quantity_requested},[prod_product_id, order_date])

d_bucket_2:

count({d_bucket_1})

I get correct count result from d_bucket_2.

I need to yield results from d_bucket_2 without doing LAC-A function, by using a LAC-W function. Is there any way to do it?

Hello @mamilone !

To clarify, do you want to keep d_bucket_1 or replace it with d_bucket_2 as a LAC-W?

If you want to replace d_bucket_1 with a LAC-W you could try the following:
countOver({outb_final_quantity_requested}, [prod_product_id, order_date])

Or if you want to to do a sum of the results from d_bucket_1 as d_bucket_2:
sumOver({d_bucket_1}, [prod_product_id, order_date], PRE_AGG)

I would also recommend checking out this blog to learn more about using these types of functions: