0

I would like to be able to show our partner (customer_organizations) rank by order count and then also by gross revenue week over week (month over month) etc. I want the output to show something like this. I'm currently writing this in Zoho Analytics

Customer_Organization Week 1 Week 2
cariloha 1 3.
avocado 2 1.
floyd 3. 2.

I originally had DATEADD - 30 in this but I can't figure out how to get week over week, month over month, etc.

SELECT
    customer_organizations.id,
    customer_organizations.name,
    COUNT(orders.id),
    RANK() OVER (ORDER BY COUNT(orders.id) DESC) Rank
FROM 
    orders
JOIN 
    customer_organizations ON orders.customer_organization_id  = customer_organizations.id  
WHERE 
    customer_organizations.status = 'enabled'
    AND customer_organization_type = 'partner'
GROUP BY 
    customer_organizations.id,
    customer_organizations.name 
ORDER BY 
    rank;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Typically you would have a date dimension to help slicing and dicing dates where the key would be a date and then have all the attributes associated with it. FY CY FM CM Week FQ CQ etc. This link is a good example of how to set one up https://www.mssqltips.com/sqlservertip/5553/create-an-extended-date-dimension-for-a-sql-server-data-warehouse/ – KeithL Jan 23 '23 at 18:56
  • 1
    Thank you! We were just discussing the need to have a date table and I was trying to find the best way to create one – Elie Janowiak Jan 24 '23 at 22:31
  • The best advantage is that all dates will be treated the same no matter where they are coming from. Also, calculating something like fiscal year when the FY starts in October for example is quite cumbersome to apply to every date instead of just joining to dimDate and using an indexed attribute. – KeithL Jan 26 '23 at 13:19

0 Answers0