Forum Discussion
SamTailor
9 years agoHelper I
Previous Transaction date DAX help
Please help me, how can I get Previous Transaction date in DAX? The data set is not that simple its is not sorted, has multimple customers with multile products, and resellers. Th...
- 9 years ago
Hey,
here is an example for a calculated column using variable instead of the EARLIER function
Previous transaction date = var currentDate = 'yourTableName[Transaction date] var currentCustomer = 'yourTableName'[Client]
var currentReseller = 'yourTableName'[Reseller]
var currentProduct = 'yourTableName'[Product] return CALCULATE(MAX('yourTableName'[Transaction date]), FILTER(ALL('yourTableName'), 'yourTableName[Date] < currentDate && 'FactWithDates'[Customer] = currentCustomer
&& 'yourTableName'[Reseller] = currentReseller
&& 'yourTableName'[Product] = currentProduct ) )- For each row the current values for Client, Reseller, and Product are stored in variables.
- CALCULATE is used to transform the existing ROWCONTEXT (we are creating a calculated column), into a FILTER CONTEXT
- The now existing FILTER CONTEXT has to be expanded, to gain access to all records using FILTER(ALL('yourTableName), ...
- The rows are filter down using the variables
- The MAX transaction date is calculated, from all Transactions date that are smaller than the date of the variable
Hope this helps
TomMartens
9 years agoSuper User
Hey,
here is an example for a calculated column using variable instead of the EARLIER function
Previous transaction date = var currentDate = 'yourTableName[Transaction date] var currentCustomer = 'yourTableName'[Client]
var currentReseller = 'yourTableName'[Reseller]
var currentProduct = 'yourTableName'[Product] return CALCULATE(MAX('yourTableName'[Transaction date]), FILTER(ALL('yourTableName'), 'yourTableName[Date] < currentDate && 'FactWithDates'[Customer] = currentCustomer
&& 'yourTableName'[Reseller] = currentReseller
&& 'yourTableName'[Product] = currentProduct ) )
- For each row the current values for Client, Reseller, and Product are stored in variables.
- CALCULATE is used to transform the existing ROWCONTEXT (we are creating a calculated column), into a FILTER CONTEXT
- The now existing FILTER CONTEXT has to be expanded, to gain access to all records using FILTER(ALL('yourTableName), ...
- The rows are filter down using the variables
- The MAX transaction date is calculated, from all Transactions date that are smaller than the date of the variable
Hope this helps