How to calculate metrics from formula builder?

Problem Statement
We are developing a metric store builder for our FP&A tool, Mantys, to enhance our customers’ data analysis capabilities. While we have successfully implemented simple metric aggregations, such as sums and averages, using cube.dev as our semantic layer, we face challenges when scaling for more complex formula metrics.

  1. Simple Metrics
  2. Formula Metrics

Example Formula Metric:
CAC Metric = OFFSET((S&M Expenses – Customer Marketing Expenses), -1)/ New Customers

Solution
Our simple metrics involve straightforward aggregations from column values, which work well with cube.dev. However, for more advanced requirements, we need formula metrics that are derived from other metrics rather than directly from tables or columns. These formula metrics incorporate various analytical functions such as Offset, If, Equals, Min, Max, Sum, BoMonth, and EoMonth.
Challenges

Scalability: Cube.dev handles simple metrics efficiently but struggles with the complexity and performance requirements of formula metrics.

Complexity: Formula metrics require combining multiple metrics and applying advanced analytical functions, which is beyond the current capabilities of our cube.dev setup.

Performance: Ensuring that these complex calculations perform well and return results in a timely manner is a significant challenge.

Flexibility: We need a solution that allows for the dynamic creation and adjustment of formula metrics without extensive rework or customization.

Approaches:

  1. Compose SQL and apply database UDFs
  2. Compose Dataframes and apply pandas/spark UDFs
  3. Low Level Metric Store implementation using Apache Druid/Apache Pinot

enter image description here

Pros:

  • This can be run against the databases as the final output is just plain SQL
  • No need for any Deployment and CI/CD pipeline automation

Limitations:

  • UDFs and UDAFs supported natively by databases can be limited
    • Functions like EOmonth won’t be supported
  • Still in this approach we depend on Cube.dev Semantic Model for creating JSON to SQL

Tools used:

  • Cube (Simple Metrics)
  • SQL (complex metrics)

Where are we in experimentation?

  • We are trying to check whether we can store the existing metrics SQL query against the store Metrics and compose the CTEs dynamically
    • Doing through trial and error for now, an agency might be able to give us the right sequence

enter image description here

Pros:

  • Since we are using programming languages like Python, we can create all the necessary UDFs and UDAFs for the metric builder.

Limitations:

  • This can’t be run against the databases, instead need to be executed against Spark/AWS EMR Clusters for large datasets: Infra challenge
  • Deployment and CI/CD pipeline automation can be complex
  • Delay in data- not real time

Tools used:

  • Cube (Simple Metrics)
  • Spark/Pandas
  • GCP DataProc/AWS EMR

Where are we in experimentation?

  • We are trying to check whether we can store the existing metrics SQL query against the store Metrics and compose the CTEs dynamically
  • How to store it effectively against the clusters? How to store and run it against dataframes?
  • Github POC Link: https://github.com/mohitPanwar1996/metric-store-builder

Approach 3: Low Level Metric Store Implementation using Apache Pinot/Druid
In this approach we explored Apache Pinot(Star Tree) and Apache Druid(Imply) for building metrics in real time during streaming/batch ingestion. But we were not able to make any progress due to the following reasons.

Pros:
Build Metrics in real time (the value will reflect in real time)

Limitations:

  • Streaming Ingestion(mostly all of these services built on Kafka)
  • Complex cloud setup
  • Table Transformations not supported
  • OBT(One Big table) approach is recommended mostly; Joining tables is not there
  • Only SQL REST API are supported not like cube.dev(check the below screenshot for reference)

Tools Used:

  • Star Tree Cloud/Imply Cloud – Processing
  • Kafka/AWS MSK/Confluent – Streaming
  • Apache Presto/Trino – Querying

Where are we in experimentation?

  • We connected with Imply and StarTree cloud team for understanding their offerings
    Tried creating measures, dimensions and metrics but we were not able to create derived metrics or formula based metrics on the fly. Need to explore.

enter image description here

Request for Advice
We are seeking advice, solutions, or recommendations from other consultants, forums, and consultancies on how to effectively implement and scale formula metrics in our system. Specifically, we are interested in best practices, tools, or strategies that could help overcome the limitations we are experiencing with cube.dev in handling these advanced use cases.

Questions where we need help?

  1. How to effectively implement the formula based metrics?

    a. We are trying to check whether we can store the existing metrics SQL query against the store Metrics and compose the CTEs dynamically for the first approach (Approach 1)

    b. How to store it effectively against the clusters? How to store and run it against dataframes? (Approach 2)

  2. How to implement the analytical functions against the formulas?

  3. How to scale this across our multi tenant architecture?

References:

In our R&D we have gone through various formulas builder that other companies are using:

  1. Mosaic: https://www.mosaic.tech/metric-builder
  2. Drivetrain: [https://docs.drivetrain.ai/formulas/formulas-in-drivetrain
  3. Causal: https://www.causal.app/](https://stackoverflow.com)
  4. IBM Formula Builder – https://www.ibm.com/docs/en/mas-cd/maximo-monitor/continuous-delivery?topic=calculations-using-simple-functions

Screenshots:
enter image description here

enter image description here

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật