Function table / Level of detail / Invoice count per customer

Invoice count per customer, from Tableau to SQL

Counts non-null invoice amounts at customer grain. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

{ FIXED [Customer] : COUNT([Revenue]) }

Sample data

RegionTeamCustomerRevenueSeatsDate
NorthCedarAster12042026-01-05
NorthCedarAster12022026-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 "Customer", COUNT(Revenue) AS result FROM input  GROUP BY "Customer" ORDER BY "Customer"

Runs the example above.

Result

Customerresult
Aster2
Birch1
Clover1
Dahlia2
Fern2

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

Where a naive translation goes wrong

  • COUNT(DISTINCT Revenue) collapses separate invoices with the same amount; COUNT keeps both.

    Naive SQL

    SELECT "Customer", COUNT(DISTINCT Revenue) AS result FROM input  GROUP BY "Customer" ORDER BY "Customer"
    Customerresult
    Aster1
    Birch1
    Clover1
    Dahlia2
    Fern2

    Matches the calculation

    SELECT "Customer", COUNT(Revenue) AS result FROM input  GROUP BY "Customer" ORDER BY "Customer"
    Customerresult
    Aster2
    Birch1
    Clover1
    Dahlia2
    Fern2

Signature

{ FIXED [Customer] : COUNT([Revenue]) }