Forum Discussion
datamodel
6 years agoAdvocate I
Crossjoin, GENERATE?
This is probably simple, but I just can't seem to figure it out. Need a way to count all Activity Type = 8 by product by customer. In the activity below, both 888 and 999 products should get a cou...
datamodel
6 years agoAdvocate I
Thank you, that helped. I modified the calc a bit to add it to a measure, instead of a new table. The below calc is able to get the correct total but the only issue is that it doesn't break it down by Product on the product dimension. It does however break it down by Customer.
ActivityCount = SUMX(
GROUPBY (
NATURALLEFTOUTERJOIN(
CALCULATETABLE(SUMMARIZE('Activity Table','Activity Table'[PRODUCT_ID],'Activity Table'[CUSTOMER_ID]),NOT(ISBLANK('Activity Table'[PRODUCT_ID]))),
SUMMARIZE('Activity Table','Activity Table'[CUSTOMER_ID],"activityCount",CALCULATE(COUNTROWS('Activity Table'),'Activity Table'[ACTIVITY_TYPE]=8))
),
'Activity Table'[CUSTOMER_ID],
"AveragePerCustomer", MAXX ( CURRENTGROUP (), [activityCount] )
),
[AveragePerCustomer]
)| PRODUCT | ActivityCount |
| 888 | (missing value) |
| 777 | (missing value) |
| 999 | (missing value) |
| Total | 7 |
| CUSTOMER | ActivityCount |
| 123 | 3 |
| 4567 | 2 |
| 78900 | 2 |
| Total | 7 |
datamodel
6 years agoAdvocate I
Figured it out by summarizing ALLSELECTED activity. Thank you jdbuchanan71 for the 90% :)
ActivityCount = SUMX(
GROUPBY (
NATURALLEFTOUTERJOIN(
CALCULATETABLE(SUMMARIZE('Activity Table','Activity Table'[PRODUCT_ID],'Activity Table'[CUSTOMER_ID]),NOT(ISBLANK('Activity Table'[PRODUCT_ID]))),
SUMMARIZE(ALLSELECTED('Activity Table'),'Activity Table'[CUSTOMER_ID],"activityCount",CALCULATE(COUNTROWS('Activity Table'),'Activity Table'[ACTIVITY_TYPE]=8))
),
'Activity Table'[CUSTOMER_ID],
"AveragePerCustomer", MAXX ( CURRENTGROUP (), [activityCount] )
),
[AveragePerCustomer]
)