Forum Discussion
Passing Slicer Selection value in DAX Filter
Thanks Felix for your reply.
I need to count the number of transactions per customer every year, then based on the selected year, we use the count of that year and the 2 previous years to determine certain status for the customer. So year selection must be dynamic and based on a slicer. Transaction count will be stored in a column (3 columns actually) for the selected year and the 2 prevoius ones.
In the calculated column, I use the following
Hi aamer ,
This can be done using measures.
I don't know how your data is structure but I assume is something similar to the one below:
Date
Tranx_NUMBER
Column1
Column2
....
ColumnN
If you have a calendar table then you can add a measure for curent year and the previous 2 year that way you would be abble to make the count and further calculations.
Measures would be similar to this:
TransSelectedYear = DISTINCTCOUNT (Revenue_Lines[TRX_NUMBER])
TransSelectedYear - 1 = VAR Year_Selection = SELECTEDVALUE(DAte[Year])
Return
CALCULATE([TransselectedYear], FILTER(ALL(Date[Year]), Date[Year )= Year_Selection - 1]))
TransSelectedYear - 2 = VAR Year_Selection = SELECTEDVALUE(DAte[Year])
Return
CALCULATE([TransselectedYear], FILTER(ALL(Date[Year]), Date[Year )= Year_Selection - 2]))
Now this measures can be used to make the calculations.
If you share a sample data I can provide a better example.
No need to create additional tables on your model except the date table.
- aamer5 years agoRegular Visitor
Thanks again for your reply..
I need the calculated table to group the transactions per customer. A measure will only calculate the transactions for the selected customer but if I need to do it for all customers I bleieve it has to be in a calculated column. This way I would be able to plot transaction count per customer.
My first step was to summarize the transactions table as follows:
CustomerTransactionsCount = SUMMARIZECOLUMNS(Revenue_Lines[Customers])Then I would add the calculated columns.Is there another way to do this calculations? - DaveNZ3 years agoNew Member
Felix - this is the correct way to do it. I was stumped on this also as intuitively you would be expected to work with the selected value expression directly. Passing in into a variable is the way to solve this. Much appreicated!