Forum Discussion
Intersect function in Dynamic Matrix
- 5 years ago
Great explanation now 🙂
I haven't looked in detail at the logic for the code for [2 Visitas x Prospectos] but one thing does stand out. Why would you repeat
IF(ISBLANK(MonthEndStore),BLANK(),COUNTROWS(INTERSECT(TableStoreVisitors, TableWebVisitors )))11 times on the switch, if the result is exactly the same for each of the 11 options?? You can simplify the switch:
2 Visitas x Prospectos V2 = VAR IDMonth = SELECTEDVALUE(ID_Month[ID] ) - 1 VAR MonthWeb = MIN('Calendar'[Date]) VAR MonthStore = MAX('Calendar'[Date]) VAR MonthIniWeb = STARTOFMONTH(DATEADD(FILTER(LASTDATE('Calendar'[Date]), 'Calendar'[Date] = MonthStore ), IDMonth,MONTH)) VAR MonthEndStore = ENDOFMONTH(DATEADD(FILTER(LASTDATE('Calendar'[Date]), 'Calendar'[Date] = MonthStore ), IDMonth,MONTH)) VAR TableWebVisitors = CALCULATETABLE( SUMMARIZE(Data,Data[Client_ID]), Data[Channel] = "Web") VAR TableStoreVisitors = CALCULATETABLE( SELECTCOLUMNS( FILTER(Data, Data[Channel] = "Store"), "Visitors",Data[Client_ID]),DATESBETWEEN('Calendar'[Date],MonthIniWeb,MonthEndStore)) RETURN IF ( SELECTEDVALUE ( ID_Month[ID] ) IN GENERATESERIES ( 1, 11 ), IF (ISBLANK ( MonthEndStore ), BLANK (), COUNTROWS ( INTERSECT ( TableStoreVisitors, TableWebVisitors ) ) ) )Note that this is functionally equivalent to what you had. Now we can create another measure that uses the measure above and that will work at the totals.
2 Visitas x Prospectos V2 TOT = SUMX ( CROSSJOIN ( DISTINCT ( 'Calendar'[Period] ), DISTINCT ( ID_Month[ID] ) ), [2 Visitas x Prospectos V2] )Place this last measure in your matrix visual 3. You might want to change it for the result at the grand total.
See it all at work in the attached file.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Here's an update. We managed to get the formula to recognize the start and end periods for each month (ID_Mes), it was just a small detail, now we are using Datesbetween. Now it correctly shows us the visits to the store in visual 3, we only need to solve the issue of the row and column totals.