Function table / Level of detail / Team share within region

Team share within region, from Tableau to SQL

Divides team revenue by its region total. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

SUM([Revenue]) / { EXCLUDE [Team] : SUM([Revenue]) }

Sample data

RegionTeamCustomerRevenueSeatsDate
NorthCedarAster12042026-01-05
NorthCedarAster8022026-02-05
NorthCedarBirch30062026-01-12
NorthPineClover9032026-02-14
SouthElmDahlia20052026-01-08
SouthElmDahlia10022026-02-08
SouthAshFern7532026-01-20
SouthAshFern2512026-02-20

The same calculation as SQL

SELECT Region, Team, SUM(Revenue)*1.0/MAX(total) FROM input JOIN (SELECT Region, SUM(Revenue) total FROM input GROUP BY Region) USING(Region) GROUP BY Region, Team ORDER BY Region, Team

Runs the example above.

Result

RegionTeamresult
NorthCedar0.847458
NorthPine0.152542
SouthAsh0.25
SouthElm0.75

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Dividing by the team subtotal produces one instead of the team share of regional revenue.

    Naive SQL

    SELECT "Region", "Team", SUM(Revenue)*1.0/SUM(Revenue) AS result FROM input  GROUP BY "Region", "Team" ORDER BY "Region", "Team"
    RegionTeamresult
    NorthCedar1
    NorthPine1
    SouthAsh1
    SouthElm1

    Matches the calculation

    SELECT Region, Team, SUM(Revenue)*1.0/MAX(total) FROM input JOIN (SELECT Region, SUM(Revenue) total FROM input GROUP BY Region) USING(Region) GROUP BY Region, Team ORDER BY Region, Team
    RegionTeamresult
    NorthCedar0.847458
    NorthPine0.152542
    SouthAsh0.25
    SouthElm0.75

Signature

SUM([Revenue]) / { EXCLUDE [Team] : SUM([Revenue]) }