Mixed functions are the ones that can form group-by of multiple columns and define different data granularities while having the ability to invoke row context over the newly formed tables. The most important one is SUMMARIZE.
SUMMARIZE is mostly used as a replacement for VALUES function when we need to create crossjoin of multiple columns from the model while accepting filter context. VALUES function can only accept a single column or the whole table as an argument, but if we need to form a table from multiple columns then SUMMARIZE is the preferred way to go.
SUMMARIZE (Table, [GroupByColumn1, GroupByColumn2, …], [[ColName1], expression, [ColName2], expression, …])
- The first argument is the table from which we wish to group columns.
- The second type of argument is a list of columns we wish to include in a grouped virtual table.
- The third type of argument is defining the new column we want to add to the virtual table with the expression that will be evaluated in a row context of the summarized table. The 3rd argument is rarely used. If we need to add an additional virtual column to the SUMMARIZE function, we should use ADDCOLUMNS function instead because, in most cases, the latter produces a faster query plan.
VALUES_Category = COUNTROWS(VALUES(Sales[CategoryName]))
VALUES can only accept a single column or a whole table as an argument, which limits its application. It accepts filter context.
ALL_Category/Region = COUNTROWS(ALL(Sales[CategoryName],Sales[SalesTerritoryRegion]))
ALL function can be used with multiple columns, but its side effect is that it ignores filter context
SUMMARIZE_Category/Region = COUNTROWS(SUMMARIZE(Sales,Sales[CategoryName],Sales[SalesTerritoryRegion]))
SUMMARIZE is the best replacement for the VALUES function when we need to cross-join multiple columns. It does that while accepting filter context.
Like with the ADDCOLUMNS function, its usefulness becomes clear after learning the power of the CALCULATE function.
SUMMARIZE can access any table in a data model connected to the table defined in the first argument, as long as that table has a one to many relationship with the main table. The data model concept will be explained in the following chapter.