How to represent a Pivot Table as a Mathematical Formula?

How do you represent a Pivot Table (as per Excel) as a mathematical mapping using set theory?

My assumption would be you're basically mapping a Cartesian Product to a count function. However, specifying the count function is where I'm unsure. This is my best attempt at doing one for a count pivot table (averages, sums etc. could be easily tweaked):

$$C = \{a_i \in \text{Type 1}\} \times \{b_i \in \text{Type 2}\}$$

$$Rows = \{r_i \in C\}$$

$$C \mapsto \sum^{|Rows|}_{i=1} c()\text{, where } c() = \begin{cases} 1,& Row_i = (a_i, b_i)\\ 0,& Row_i \neq (a_i, b_i)\end{cases}$$

Is there a simpler way, or clearer more rigorous way?

How can you explicitly declareRows as a multiset?

Full disclosure, my university was pretty bad at providing a good set theoretic background. So my apologies.

For each column in a table, there is some set it takes its values from. For example, one column could consist of arbitrary real numbers - the set $$\Bbb R$$, another column could be a fixed list of possible values of arbitrary type: $$\{$$East, West, South, North$$\}, \{$$Doris, Kirsten, Scot, Gerry, Lori$$\}$$, etc. Label the set for column number $$c$$ as $$S_c$$.
A Table of size $$n$$ subordinate to the set sequence $$(S_c)_{c=1}^m$$ is then a function $$T : \{1,2, ..., n\}\times\{1,2, ..., m\} \to \bigcup_{c=1}^m S_c$$ that satisfies the condition that for all $$r$$ and $$c, T(r,c) \in S_c$$.
Let $$\mathscr T((S_c)_{c=1}^m)$$ be the collection of all tables (of any size) subordinate to $$(S_c)_{c=1}^m$$. If $$(\hat S_c)_{c=1}^k$$ is another collection of sets, then a Pivot Table is simply a map $$PT: \mathscr T((S_c)_{c=1}^m) \to \mathscr T((\hat S_c)_{c=1}^k)$$
that is, it is some established method of converting a table subordinate to $$(S_c)_{c=1}^m$$ into a table subordinate to $$(\hat S_c)_{c=1}^k$$