About Me Projects Articles Experience Education Contact
Resume PDF Switch to Portuguese 🇧🇷
Back to Projects
DATA SCIENCE NLP & AI DECISION INTELLIGENCE

Analytics Engineering & NLP: Churn Diagnostics and Financial Risk in SaaS

How I architected a hybrid solution (Python + Power Query) to process 45,000 reviews via Generative AI, applying statistical rigor to calculate Revenue at Risk (MRR) and guide the C-Suite.

Nov 2026 18 min read Power BI, Python, Hugging Face, DAX

Executive Dashboard: Customer Feedback Analytics (Deep Violet Theme)

Live
100% Bilingual Architecture (PT/EN) GDPR/LGPD Compliance (Art. 12)

Tech Stack Used in this Project

Power BI (M & DAX)
Python (Pandas)
Hugging Face API (NLP)
Statistics (Cochran)

1. The Executive Challenge: The Churn "Black Box"

GenSoft, a tech company operating under the SaaS (Software as a Service) model, reached the 20,000 active customers milestone. However, rapid growth brought a severe side effect: a critical spike in churn rates and a flood of negative feedback across public channels and support tickets.

The board needed quick answers to three fundamental questions that defined the business's future:

  • 1. Which audience is most likely to leave negative reviews?
  • 2. What are the actual drivers behind this dissatisfaction?
  • 3. What is the immediate financial impact if we don't act?

The core issue wasn't a lack of data, but the inability to process it. With a historical database of over 45,000 free-text reviews (natural language), the board was flying blind. Reading and categorizing this volume manually was humanly impossible. My mission as an Analytics Solutions Architect was to decode this mass of unstructured data and build a prescriptive Data Product.

2. The Architectural Hurdle: API and Network Limitations

The obvious solution would be connecting the database to an AI API (like OpenAI) to perform Sentiment Analysis and Topic Modeling. However, in the real world of Data Engineering, we hit critical roadblocks:

  • Cost and Rate Limits: Free APIs (like Hugging Face's Inference API) have strict limits. Sending 45,000 simultaneous requests would result in an immediate IP block (Error 429 - Too Many Requests).
  • Power BI Network Isolation: The Python script execution environment inside Power Query has severe DNS resolution restrictions, preventing direct HTTP calls via the requests library.

To bypass these limitations, I designed a Hybrid Architecture. Python was used strictly for local in-memory processing (Statistical Sampling), while the M language (Power Query) took over the network request responsibility via Web.Contents, bypassing the internal firewall.

3. The Statistical "Hack": Cochran's Formula

To avoid exhausting API requests and optimize model refresh time from hours to minutes, I applied a fundamental Data Science concept: you don't need to drink the ocean to know the water is salty.

I utilized Cochran's Formula with Finite Population Correction. Assuming a 95% Confidence Level and a 5% Margin of Error, the Python script reduced the 45,218-row database to a stratified sample of just 380 records. This slashed cloud processing volume by over 99% while keeping mathematical accuracy intact.

The Statistical Rationale

How did we reach the 380-record sample?
The original dataset has an exact population of 45,218 reviews. To avoid the bias of analyzing only a specific topic (as done in simplified approaches), I applied Cochran's Formula for finite populations with the following parameters:

  • Confidence Level (Z): 95% (Ensures the result reflects reality the vast majority of the time).
  • Margin of Error (e): 5% (Acceptable variance for decision-making).
  • Proportion (p): 0.5 (Ensures maximum variance and the safest possible sample).

Result: Stratified sampling ensured that the proportion of scores and topics in the 380-row sample was a perfect mirror of the 45,000-customer population, validating the financial Upscaling of the simulator.

Python (Power Query)
import pandas as pd
import numpy as np

df = dataset.copy()

# 1. COCHRAN'S FORMULA PARAMETERS
Z = 1.96          # 95% Confidence Level
p = 0.5           # Expected proportion (maximum variance)
e = 0.05          # 5% Margin of Error
N = len(df)       # Total population (45,218)

# 2. SAMPLE CALCULATION WITH FINITE CORRECTION
n0 = (Z**2 * p * (1-p)) / (e**2)
n = int(np.ceil(n0 / (1 + (n0 - 1) / N)))

# 3. STRATIFIED SAMPLING (Maintaining original score proportions)
sample = df.groupby('Original Score', group_keys=False).apply(
    lambda x: x.sample(n=max(1, int(np.round(len(x) / len(df) * n))), random_state=42)
).reset_index(drop=True)

4. Generative AI Integration (Hugging Face)

With the sample perfectly isolated, I built a custom M Language function to query Hugging Face's modern router (router.huggingface.co).

I used the nlptown/bert-base-multilingual-uncased-sentiment model, optimized for multiple languages. The M function sends the text, receives the classification (1 to 5 stars), and applies GenSoft's business rules to translate the output into "Positive", "Neutral", or "Negative".

5. Machine Learning in Action: Key Influencers

Technical Note: Microsoft blocks the rendering of native AI visuals (like Key Influencers) in public links due to API security. To demonstrate the ML model's capability generated in Power BI, I recreated the algorithm's behavior below using HTML/JS, reflecting the exact insights discovered in GenSoft's database.

Key Influencers Analysis

What influences Rating to be Low ⌄ ?

When... Likelihood increases by

Role is

Consumer

1.28x

Plan is

Premier

1.25x

Tutorial Completed is

No

1.18x
Rating is more likely to be Low when Role is Consumer than otherwise (on average).

Business Insight

This segment represents the end-users of the platform. Their dissatisfaction is highly correlated with usability and speed issues, indicating a gap between the buyer's expectation (Admin) and the user's reality.

Average: 29.2%
36.7%
Consumer
Administrator
Editor

6. Data Modeling and Decision Intelligence (DAX)

The model was structured in a rigorous Star Schema. To ensure dashboard internationalization (i18n) without duplicating pages, I implemented a 100% bilingual architecture using Disconnected Tables and Field Parameters.

The major differentiator of this project for the board was the creation of a Financial Simulator (What-If Parameters). Instead of just showing past Churn, the dashboard allows the C-Suite to adjust plan prices (Basic, Premier, Deluxe) in real-time to forecast the financial impact of dissatisfaction.

For the calculation to be mathematically sound, the DAX measure had to perform Upscaling (Statistical Extrapolation), multiplying the sample result by the population factor.

DAX
Simulated_Revenue_at_Risk = 
// 1. Calculate Extrapolation Factor (Population / Sample)
VAR Extrapolation_Factor = DIVIDE(MAX(fReviews[_Total_Population]), MAX(fReviews[_Sample_Size]), 1)

// 2. Calculate simulated revenue iterating over the plans table
VAR Simulated_Sample_Revenue = 
    SUMX(
        dPlans,
        VAR Qty_Negative_Reviews = 
            CALCULATE(COUNTROWS(fReviews), fReviews[fnGetSentiment] = "negative")
        VAR Simulator_Value = 
            SWITCH(
                dPlans[Plan Type],
                "Basic", [Basic Plan Simulator Value],
                "Premier", [Premier Plan Simulator Value],
                "Deluxe", [Deluxe Plan Simulator Value], 0
            )
        RETURN Qty_Negative_Reviews * Simulator_Value
    )

// 3. Project the real value for the entire base
RETURN Simulated_Sample_Revenue * Extrapolation_Factor

7. Executive Answers and Action Plan

Semantic analysis, the interactive Treemap, and data modeling accurately answered the board's questions, shifting GenSoft's strategic direction:

Who cancels?

AI proved that the End Consumer (not the Administrator) on the Premier Plan is the biggest detractor. Churn risk increases by 1.28x in this segment.

Why do they cancel?

Cross-referencing SLA vs. CSAT (Scatter Plot) and the Treemap pointed to System Sluggishness (Speed) and lack of Onboarding as the biggest offenders.

Prescriptive Action

It was recommended to make the tutorial mandatory for the Basic plan (reducing tickets) and to review the pricing of the Premier plan, which generated high expectations but low delivery.

This case demonstrates that the true value of Analytics doesn't lie in plotting charts, but in orchestrating Data Engineering, Statistics, and Artificial Intelligence to protect company revenue and guide executive decision-making.

Enjoyed the analytical depth of this project?

Share this Analytics Engineering and NLP case with your professional network.

Does your organization need to align Data, AI, and Business Strategy?

Talk to Darlan