Forum Discussion
DATEADD with slicer parameter
I have a table with the following example data:
| NATURE | DATE1 |
| NOTEBOOK | 2016.01.01 |
I would like to add a column, which is generated based on these:
If the NATURE column has "NOTEBOOK" in it, add X years to DATE1 column.
X value is depended on a slicer value which you can choose in the visualization.
I was trying to do this with several methods, but nothing seems to work.
Can you help?
Thanks.
Hi Anonymous
try this, create the measure
date2 = var _addY=SELECTEDVALUE(Slicer[Rollout years]) var _year=EDATE(MIN('Table'[date1]),_addY*12) return _yearresult
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- amitchandak
Super User
Anonymous , You need to create create a measure
datediff(max(Table[Date1]) ,maxx(allselected(date),date[date]), day)
In case you want to add or avg
you need
sumx(values(Table[NATURE]), datediff(max(Table[Date1]) ,maxx(allselected(date),date[date]), day) )
- AnonymousNot applicable
amitchandak Unfortunately, this isn't working.
Maybe I wasn't clear, let me reelaborate, this is my data source:
inventory number nature date1 date2 a1 NOTEBOOK 2016.01.01. a2 MOBILE 2017.02.01 a3 NOTEBOOK 2019.05.01. I would like to calculate a column "date2" (or a measure if its better) that adds X years to "date1" column.
The value X is chosen with a slicer like this:
So if I set 3 years in the slicer, the first row's date2 column would be 2019.01.01, but if I set 3.5 or 4 years, the date2 column would update accordingly.
My final goal is to count these values by inventory numbers in a matrix visualsation according to date2.
Thanks in advance!
- v-xiaotang
Community Support
Hi Anonymous
try this, create the measure
date2 = var _addY=SELECTEDVALUE(Slicer[Rollout years]) var _year=EDATE(MIN('Table'[date1]),_addY*12) return _yearresult
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.