Data Driven Insights

Data Driven Insights "Unlock the power of data! πŸ“Š From Excel tricks to SQL queries and Python automationβ€”master the skills that drive insights.
(1)

Follow for tips, tutorials, and more! "

https://linktr.ee/datadriveninsights

20/09/2025

⚑ PYTHON HACK – Use itertools.filterfalse to Invert Conditions

from itertools import filterfalse

nums = [10, 15, 20, 25, 30]
odds = list(filterfalse(lambda x: x % 2 == 0, nums))
print(odds) # [15, 25]

πŸ”Ž WHAT IT DOES
βœ… Keeps items where the condition is False
βœ… Acts like the opposite of filter()
βœ… Works with any iterable

πŸ›  USAGE
β€” Extracting invalid records
β€” Separating data into matches vs non-matches
β€” Quick negative filtering in pipelines

πŸ’‘ WHY IT MATTERS
⟢ Avoids clunky not conditions in filters
⟢ Cleaner and more expressive than list comprehensions with negatives
⟢ Ideal for validation and preprocessing steps

πŸ“š TRIVIA
In Python 2.x, this was called itertools.ifilterfalse. In Python 3, renamed to filterfalse().

βš™οΈ COMPATIBILITY
βœ… Python 3.x
β›” Not directly available in Python 2.x without ifilterfalse

19/09/2025

⚑ EXCEL HACK – Return the Minimum Numeric Value That Meets Multiple Conditions

Need the lowest number for a region-product pair?

Use this formula:

=MIN(FILTER(C2:C100,(A2:A100="North")*(B2:B100="Product A")*ISNUMBER(C2:C100)))

πŸ”Ž WHAT IT DOES
βœ… Filters column C where Region = "North" and Product = "Product A"
βœ… Excludes blanks and text entries
βœ… Returns the smallest numeric value from that subset

πŸ›  USAGE
β€” Find the lowest sales figure for a region
β€” Track minimum KPI scores by category
β€” Automate β€œworst-case” dashboards

πŸ’‘ WHY IT MATTERS
⟢ Simpler than old MIN(IF(...)) array formulas
⟢ Ensures only numeric values are considered
⟢ Perfect for identifying underperformers

πŸ“š TRIVIA
Pair this with MAX(FILTER(...)) to create a high-low range check.
Great for spotting performance spreads in a dataset.

βš™οΈ COMPATIBILITY
βœ… Excel 365 / Excel 2021 (FILTER required)
β›” Not supported in older versions without Ctrl+Shift+Enter arrays

πŸ“Š Olympics Sports Analytics β€” Post  #6: Tracking Streaks & Performance GapsAthletes rarely compete just once β€” coaches w...
19/09/2025

πŸ“Š Olympics Sports Analytics β€” Post #6: Tracking Streaks & Performance Gaps

Athletes rarely compete just once β€” coaches want to know whether they’re improving, declining, or holding steady over time.

In this post, we use LAG() and LEAD() window functions to track trends in results:

βœ… LAG() compares the current performance to the previous one
βœ… LEAD() looks ahead for projections
βœ… CASE logic interprets results as Improved, Declined, Same, or First appearance
βœ… Partitioning ensures times (seconds) aren’t mixed with weights (kg)

Example insights:

First race β†’ β€œFirst appearance”

Faster than last race β†’ β€œImproved”

Slower than last race β†’ β€œDeclined”

Takeaway: LAG() and LEAD() turn raw numbers into trends β€” perfect for progress dashboards, scouting reports, or injury recovery tracking.

πŸ”œ Next in Post #7: Per-segment splits analysis with UNPIVOT and JSON parsing to measure pace consistency.

19/09/2025

⚑ GOOGLE SHEETS HACK – Display Current Date in Custom Format

Want today’s date to show in a custom style (like 11-Sep-2025)? Use:

=TEXT(TODAY(),"dd-mmm-yyyy")

πŸ”Ž WHAT IT DOES
βœ… Converts today’s date into a custom format
βœ… Works with any valid date
βœ… Updates automatically each day

πŸ›  USAGE
β€” Show dates neatly in reports
β€” Format logs for readability
β€” Match regional date styles

πŸ’‘ WHY IT MATTERS
⟢ Gives full control over how dates appear
⟢ No need to adjust cell formatting manually
⟢ Makes reports professional and clear

πŸ“š TRIVIA
You can use "mmmm yyyy" to show just the month and year (e.g., September 2025).

βš™οΈ COMPATIBILITY
βœ… Works in Google Sheets and Excel

πŸ“Š Olympics Sports Analytics β€” Post  #5: Qualification Rules β€” Top-N + Fastest LosersOlympic qualifiers don’t always work...
19/09/2025

πŸ“Š Olympics Sports Analytics β€” Post #5: Qualification Rules β€” Top-N + Fastest Losers

Olympic qualifiers don’t always work on simple β€œTop N per heat.” Often, athletes advance if they:
1️⃣ Finish in the top spots of their heat, and
2️⃣ Are among the fastest losers across all heats.

In this post, we built a query that combines both rules:

βœ… ROW_NUMBER() to rank athletes within each heat
βœ… Selected the top 2 per heat
βœ… Added the next 2 fastest overall (fastest losers)
βœ… Used indexes for fast lookups on performance

Example outcomes from our seeded 100m data:

Heat 1 β†’ Noah Williams (USA), Liam Dupont (FRA)

Heat 2 β†’ Sora Tanaka (JPN), Amina Kiptoo (KEN)

Fastest losers β†’ Marco Bianchi (ITA), Elena Rossi (ITA)

Takeaway: With ROW_NUMBER() + TOP, you can reproduce the real Olympic qualification process β€” fair, flexible, and production-ready.

πŸ”œ Next in Post #6: Detecting streaks and performance gaps using LAG() and LEAD().

19/09/2025

⚑ SQL HACK – Get the Nth Value in a Group with NTH_VALUE()

Need to fetch the 1st, 2nd, or Nth record within each groupβ€”like the 2nd highest sale per region?
Use NTH_VALUE() with window functions for precise control:

SELECT
region,
NTH_VALUE(sales, 2) OVER (
PARTITION BY region
ORDER BY sales DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS second_highest_sale
FROM sales_data;

πŸ”Ž WHAT IT DOES
βœ… Retrieves the Nth row within each ordered group
βœ… Works for any column (numeric, date, text)
βœ… Flexible for ranking-style analytics

πŸ›  USAGE
β€” 2nd best-selling product per region
β€” 3rd most recent login per user
β€” Nth milestone in performance tracking

πŸ’‘ WHY IT MATTERS
⟢ Cleaner than subqueries for Nth values
⟢ Works seamlessly with partitions and ordering
⟢ Essential for advanced analytics and BI

πŸ“š TRIVIA

NTH_VALUE(col, 1) = FIRST_VALUE()

Requires window frame specification for correct results

Alternative: ROW_NUMBER() + filtering for more control

βš™οΈ COMPATIBILITY
βœ… SQL Server, PostgreSQL, Oracle, MySQL 8.0+
β›” Not supported in older MySQL/SQLite

πŸ“Š Olympics Sports Analytics β€” Post  #4: From Heats to FinalsNot every Olympic event goes straight to the final β€” most ha...
19/09/2025

πŸ“Š Olympics Sports Analytics β€” Post #4: From Heats to Finals

Not every Olympic event goes straight to the final β€” most have heats or qualifiers. In this post, we show how to model heats and advance athletes fairly.

βœ… New event_entries table to store heat results
βœ… Used ROW_NUMBER() to rank athletes within each heat
βœ… Advanced the top 2 per heat to the next round
βœ… Guaranteed data quality with constraints (no duplicate athlete per heat)

Example outcomes from our seeded data:

Heat 1 β†’ Noah Williams (USA), Liam Dupont (FRA) advance

Heat 2 β†’ Sora Tanaka (JPN), Amina Kiptoo (KEN) advance

Takeaway: ROW_NUMBER() is the clean, production-ready way to rank competitors and handle progression logic in tournaments.

πŸ”œ Next in Post #5: Combine position-based qualifiers with time-based fastest losers to mimic real Olympic rules.

19/09/2025

⚑ PYTHON HACK – Use itertools.starmap for Multi-Argument Functions

from itertools import starmap
import operator

pairs = [(2, 5), (3, 7), (4, 9)]
results = list(starmap(operator.mul, pairs))
print(results) # [10, 21, 36]

πŸ”Ž WHAT IT DOES
βœ… Applies a function to unpacked tuple arguments
βœ… Cleaner than using map() with a lambda
βœ… Works with any multi-argument function

πŸ›  USAGE
β€” Applying math operations to value pairs
β€” Transforming datasets with multiple fields
β€” Simplifying pipelines with tuple data

πŸ’‘ WHY IT MATTERS
⟢ Eliminates the need for explicit unpacking
⟢ More concise and expressive than alternatives
⟢ Perfect for analytics and functional workflows

πŸ“š TRIVIA
starmap() is part of Python’s itertools module. Its name comes from the β€œ*” (star) unpacking operator it mimics.

βš™οΈ COMPATIBILITY
βœ… Python 2.3+ and all Python 3.x versions
β›” Input must be an iterable of tuples or sequences

πŸ”’ Python Snippet: Password Generator (Production-Ready)Need strong, secure passwords for your apps or accounts?This snip...
19/09/2025

πŸ”’ Python Snippet: Password Generator (Production-Ready)

Need strong, secure passwords for your apps or accounts?
This snippet uses Python’s secrets module to generate cryptographically safe passwords.

βœ… Secure against brute-force attacks
βœ… Configurable length & symbols
βœ… Includes type hints & error handling
βœ… Perfect for account setups, API keys, and authentication

πŸ’‘ Example Output:
βœ… Strong Password: v9@NqL7*Za1!rX2Q

A must-have utility for real-world projects where security matters most πŸš€

19/09/2025

⚑ EXCEL HACK – Return the Maximum Numeric Value That Meets Multiple Conditions

Need the highest number for a region-product pair?

Use this formula:

=MAX(FILTER(C2:C100,(A2:A100="North")*(B2:B100="Product A")*ISNUMBER(C2:C100)))

πŸ”Ž WHAT IT DOES
βœ… Filters column C where Region = "North" and Product = "Product A"
βœ… Ignores blanks and text entries
βœ… Returns the largest numeric value from that subset

πŸ›  USAGE
β€” Find peak sales for a product in a region
β€” Track maximum KPI under conditions
β€” Build dashboards showing best performance

πŸ’‘ WHY IT MATTERS
⟢ Cleaner than legacy MAX(IF(...)) array formulas
⟢ Ensures only numeric values are considered
⟢ Perfect for high-performance analytics

πŸ“š TRIVIA
Pair with MIN(FILTER(...)) to get the lowest numeric value under the same conditions.
Great for quick high-low comparisons in reports.

βš™οΈ COMPATIBILITY
βœ… Excel 365 / Excel 2021 (FILTER required)
β›” Not supported in older Excel without Ctrl+Shift+Enter arrays

19/09/2025

⚑ GOOGLE SHEETS HACK – Get Today’s Date and Time Together

Want to display the current date and exact time in one cell? Use:

=NOW()

πŸ”Ž WHAT IT DOES
βœ… Returns both today’s date and the current time
βœ… Updates automatically whenever the sheet recalculates
βœ… Works in any cell without manual typing

πŸ›  USAGE
β€” Timestamp dashboards
β€” Track log entries in real-time
β€” Monitor deadlines or events

πŸ’‘ WHY IT MATTERS
⟢ Keeps sheets always time-aware
⟢ Eliminates manual updates
⟢ Perfect for reports and trackers

πŸ“š TRIVIA
Use =TODAY() if you only need the date without the time.

βš™οΈ COMPATIBILITY
βœ… Works in Google Sheets and Excel

πŸš€ JavaScript Snippet β€” Find Difference of Two ArraysWhen working with data, you often need to compare two lists and figu...
19/09/2025

πŸš€ JavaScript Snippet β€” Find Difference of Two Arrays

When working with data, you often need to compare two lists and figure out what’s missing or unique to one of them.
Here’s a clean modern vanilla JS approach using Set for efficient lookups:

const difference = (a, b) => {
const setB = new Set(b);
return a.filter(x => !setB.has(x));
};

✨ Why this is useful:

πŸ” Find items present in one list but not in another

πŸ“Š Compare datasets (e.g., users, products, IDs)

⚑ O(n) performance with Set instead of nested loops

Example Output:

difference([1,2,3,4], [3,4,5,6]) β†’ [1,2]

difference([3,4,5,6], [1,2,3,4]) β†’ [5,6]

difference(["apple","banana","cherry"], ["banana","date"]) β†’ ["apple","cherry"]

Address

London

Alerts

Be the first to know and let us send you an email when Data Driven Insights posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Share