I have one table that has three columns: lisa, customers and activity_type. I want to count the number of rows by customer and activity type and then average them over all customers by activity types. If this were a table in sql, I'd do
SELECT
lisa,
customer,
activity_type,
average(ct)
FROM
(
SELECT
lisa,
customer,
activity_type,
CASE
WHEN
s.ct IS NULL
THEN
0
ELSE
s.ct
END
ct
FROM
(
SELECT
*
FROM
(
SELECT DISTINCT
lisa,
customer
FROM
TABLE
)
,
(
SELECT DISTINCT
activity_type
)
)
LEFT JOIN
(
SELECT
lisa,
customer,
activity_type,
COUNT(*) ct
FROM
TABLE
GROUP BY
1,
2,
3
)
s
)
s
But it's Dax, which is infinitely harder. I tried:
=
AVERAGEX(
ADDCOLUMNS(
CROSSJOIN( VALUES( Query1[customer] ), VALUES( Query1[activity_type] ) ),
"C", CALCULATE( COUNTA( Query1[engagio_activity_id] ) + 0 )
),
IF( [C] = BLANK(), 0, [C] )
)
and
=
AVERAGEX(
ADDCOLUMNS(
SUMMARIZE( Query1[lisa], Query1[activity_type] ),
"C", CALCULATE( COUNTA( Query1[engagio_activity_id] ) + 0 )
),
IF( [C] = BLANK(), 0, [C] )
)
But try as I might, I still get:
Where the blanks are not treated as 0 in the aggregate rows such as the "no" row in the picture above. That roll up amount ignores the blanks when calculating the averages. When I put the cross join into the dax studio, I forced the 0's