Best Of
Re: % Sold of Available Inventory (aka Sell-Through)
consider using window functions to get the desired result.
if you UNION your data (Consumption UNION to Inventory with a column activity_type = "consumption" or "inventory" so you can tell them apart) as @MarkSnodgrass recommended and structure your data such that you have Activity_Date and Activity_YearMonth,
you could construct your metric as a window function
sum(sum(consumption_amount)) over (partition by item, activity_yearMonth order by activity_date asc) -- this will give you the cumulative sum of your consumption for the month.
sum(sum(inventory)) over (partition by item, activity_yearMonth order by activity_date asc) will give you available inventory.
you can either choose to include activity_yearMonth in the partition clause or exclude depending on if you want the counter to reset every month.
Re: % Sold of Available Inventory (aka Sell-Through)
@chapman Not sure if this will work 100% or not, but it's a crazy idea I just had. In your ETL, after your join could you just do a formula that calculates for each row what the percentage is? Then in your card, just do a sum of the percentages? Ex for Store A:
(1/50)+(1/50)+(1/50)+(3/50)= 6/50 = 12%
is the same as:
(1+1+1+3)/50 = 6/50 = 12%
Hopefully I remember enough about math that I'm not being wildly incorrect. I think if you're just doing a simple sum, it should work.
Re: % Sold of Available Inventory (aka Sell-Through)
Do you not have a date in your inventory table? You can always add a date in the etl process, such as the first day of the month. There are several different ways you can derive a date dynamically depending on your data. You can give it the same column name as your orders table date column so that the filtering will work.
Re: % Sold of Available Inventory (aka Sell-Through)
A second option is to not join your data in the ETL, but union your data with the append rows tile. Choose include all columns when appending. This will keep your inventory rows from repeating and then you should be able to use SUM(orderqty) / SUM(qtyavail) to get the percent sold.
Re: % Sold of Available Inventory (aka Sell-Through)
You can get around the fact that the qtyAvail is repeating by using the average function in your beast mode like this:
SUM(orderQty) / AVG(`qtyAvail`)
Re: Rank based on 2 metrics?
In your OVER clause, you should be able to add ORDER BY and list current run DESC, total current run DESC so that it will sort by current run first and then total current run after that.
Re: Beast Mode Formula for Previous Complete Weeks
@MarkSnodgrass and @RocketMichael the risk with LAG() is that if you have a gap in your data (i.e. sales on 6 out of 7 days) that would throw off LAG because LAG 7 would actually be the 8th day back.
instead you might consider trying to use Variables (beta feature maybe GA check with your CSM) to address the problem.
basically you define a variable report_date which you can then alter for all of your calcs
avg_rolling_14 = sum(case when trans_date >= date_add(report_date interval -14 days) and trans_date < report_date then amount end) / count(case when trans_date >= date_add(report_date interval -14 days) and trans_date < report_date then report_date end)
in this example report_date is user define-able and you're calculating total sales within 14 days divided by the number of days of sales within 14 days.
Only hitch in the plan is that Domo does not support Dates as variables so you have to use current_date - date_offset as a surrogate for report date.
in other words your variable is date_offset and replace all instances of "report_date" above with...
date_add(today(), interval - date_offset days)
this is pseudo code so test it, but it should work with a little tweaking :D
Re: Period Over Period Calculation Challenges
( (CASE when `Period Type`='Current' then `Shipped CoGS`end) - (CASE when `Period Type`= 'Last Month' then `Shipped CoGS` end) ) / (CASE when `Period Type`='Last Month' then `Shipped CoGS`end)
you are calculating your beast mode at the row level. in other words, take one row in isolation and then apply your beast mode to it.
you Period Type for one row cannot be both 'Current' AND 'Last Month' at the same time. therefore it is IMPOSSIBLE for one row to return a result.
you have to apply your beast mode to an aggregate (which is exactly what @RobSomers ) is demonstrating.
( SUM(CASE when `Period Type`='Current' then `Shipped CoGS`end) - SUM(CASE when `Period Type`= 'Last Month' then `Shipped CoGS` end) ) / SUM(CASE when `Period Type`='Last Month' then `Shipped CoGS`end)
"across all rows take the sum of shipped cogs when period type is current."
"across all rows take the sum of shipped cogs when period type is last month" etc.


