Forum Discussion
First Touch Attribution DAX Measure with end-user filter
I have a DB with Sessions as this:
| Lead_id__c | Session_Start_Time__c | First Lead Conversion Session Time | Session ID | Channel | Traffic Type |
| x1 | 11/18/2019 18:32 | 11/26/2019 0:00 | s100 | Non-Direct | |
| x1 | 11/19/2019 19:26 | 11/26/2019 0:00 | s101 | Yahoo | Non-Direct |
| x1 | 11/25/2019 20:26 | 11/26/2019 0:00 | s102 | Direct | Direct |
| x3 | 7/20/2019 6:11 | 1/15/2020 0:00 | s108 | Direct | Direct |
| x3 | 11/21/2019 22:50 | 1/15/2020 0:00 | s105 | Non-Direct | |
| x3 | 5/15/2020 9:38 | 1/15/2020 0:00 | s106 | Non-Direct | |
| x3 | 7/19/2020 18:10 | 1/15/2020 0:00 | s107 | Yahoo | Non-Direct |
| x3 | 7/23/2020 6:24 | 1/15/2020 0:00 | s109 | Direct | Direct |
| x3 | 7/23/2020 8:10 | 1/15/2020 0:00 | s110 | Direct | Direct |
| x3 | 8/2/2020 15:46 | 1/15/2020 0:00 | s111 | Non-Direct | |
| x3 | 8/3/2020 7:18 | 1/15/2020 0:00 | s112 | Search | Non-Direct |
I would like to have a measure that counts the first session per "Channel" that was before or at the same time as "First Lead Conversion Session Time". I would also like to have a user filter on "traffic type", this filter will impact the 1 st session time as some potential sessions that were first might be filtered out.
This is what I have tried so far:
-First--
I have created a calculated column in the table "session order rank by Lead ID]" that ranks the sessions by dates per lead ID.
-Then-
TOPN(1,'Lead Attribution','Lead Attribution'[session order rank by Lead ID],ASC)
---
This gives me this:
I expected this:
| Filter = Non-Direct | |
| Row Labels | First Touch |
| 1 | |
| 1 | |
| Grand Total | 2 |
| Filter = Direct | |
| Row Labels | First Touch |
| Direct | 2 |
| Grand Total | 2 |
| No Filter | |
| Row Labels | First Touch |
| Direct | 1 |
| 1 | |
| Grand Total | 2 |
Any suggestions? PBX File : https://www.dropbox.com/t/dNHdObA0HFUjVDwB
Hi Anonymous ,
That has to do with the context replace your measure by:
Counts Lead IDs FirstLead = VAR MinimumDatesTable = ADDCOLUMNS ( SUMMARIZE ( 'DIm Channel', 'DIm Channel'[Channel] ), "@DateMin", MIN ( 'Lead Attribution'[First Lead Conversion Session Time] ) ) VAR MinStarDateSelection = MINX( MinimumDatesTable, [@DateMin] ) VAR MinStarSessionStartTime = CALCULATE(MIN('Lead Attribution'[Session_Start_Time__c]),ALLEXCEPT('Lead Attribution','Lead Attribution'[Lead_id__c],'Lead Attribution'[Traffic Type])) VAR AttributionFiltered = FILTER ( 'Lead Attribution', 'Lead Attribution'[Session_Start_Time__c] = MinStarSessionStartTime&&'Lead Attribution'[Session_Start_Time__c]<=MinStarDateSelection ) VAr CountAXX =COUNTAX( AttributionFiltered ,DISTINCTCOUNT('Lead Attribution'[Lead_id__c]) ) Return IF(HASONEVALUE('DIm Channel'[Channel]),CountAXX,SUMX(ALLSELECTED('Lead Attribution'[Lead_id__c]),CountAXX))This may need some changes around the SUMX part.
7 Replies
- MFelix
Super User
Hi Anonymous ,
Not really sure if I understand the logic based on your data because I cannot reach the result you present on the end of your post.
I have created the following measure:
Counts Value FirstLead = VAR MinimumDatesTable = ADDCOLUMNS ( SUMMARIZE ( 'DIm Channel'; 'DIm Channel'[Channel] ); "@DateMin"; MIN ( 'Lead Attribution'[First Lead Conversion Session Time] ) ) VAR MinStarDateSelection = MINX ( MinimumDatesTable; [@DateMin] ) VAR AttributionFiltered = FILTER ( 'Lead Attribution'; 'Lead Attribution'[Session_Start_Time__c] <= MinStarDateSelection ) RETURN COUNTROWS ( AttributionFiltered )Result is on attach file.
If this is not the expected result can you share what are the lines that are counting for each of the calculations you present and how you select that is that line.
What I assume in my calculation is that you pick up for each channel what is the lowest First Lead and then all the dates that are lower than that.
for the No filter I have picked up the following lines:
Lead_id__c Session_Start_Time__c First Lead Conversion Session Time Session ID Channel Traffic Type x1 18/11/2019 18:32 26/11/2019 00:00 s100 Google Non-Direct x1 19/11/2019 19:26 26/11/2019 00:00 s101 Yahoo Non-Direct x1 25/11/2019 20:26 26/11/2019 00:00 s102 Direct Direct x3 20/07/2019 06:11 15/01/2020 00:00 s108 Direct Direct x3 21/11/2019 22:50 15/01/2020 00:00 s105 LinkedIn Non-Direct - AnonymousNot applicable
MFelix You are on to something. This is how I end up with my expected filtered results. I guess the inclusion of the "First Lead Conversion Session Time" is superfluous in this calculation but is important when I will do the same for the last touch happening before or at "First Lead Conversion Session Time".
- MFelix
Super User
Hi Anonymous ,
Sorry but still not getting wath is the dates you want to compare and with what values.
Looking at you data what is the minimum date that you compare to and why you consider one date or not in your calculation.
I'm only confused about why you consider some dates, for example when you have no filter why is the value consider the 18 November and not July 20? Is it because the Sesseion is lower or because the first lead is lower?