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
Hi AlB ,
This is the link to the updated pbix Pbix
Yes, the measurement is the one that goes in visual 3 (matrix).
This is the explanation for the case of web visitors from 01-2020, on that date there were 4 web clients, the clients who visited the web in that month were Client_ID 1, 2, 6, 9
In the matrix we must see the first column (01-2020) and row 1 that represents the same month (01-2020), there you can see that that month there were 5 visits to the store, the customers who visited that date (from the 4 web clients) those 5 visits were made by 3 of them (Clien_ID 1, 2, 9).
From the same 4 web clients, only two of them (Clien_ID 6, 9) visited the store in February 2020 (row 2 in the matrix)
And only 3 client (Clien_ID 1, 2, 6) visited the store in March 2020 (row 3 in the matrix)
I hope I have been clearer with this explanation