Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

DATEADD with slicer parameter

I have a table with the following example data:

NATUREDATE1
NOTEBOOK2016.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 _year

    result

     

    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

  • 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)  )

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak Unfortunately, this isn't working.

      Maybe I wasn't clear, let me reelaborate, this is my data source:

      inventory numbernaturedate1date2
      a1NOTEBOOK2016.01.01. 
      a2MOBILE2017.02.01 
      a3NOTEBOOK2019.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's avatar
        v-xiaotang
        Icon for Community Support rankCommunity Support

        Hi Anonymous 

        try this, create the measure

        date2 = 
        var _addY=SELECTEDVALUE(Slicer[Rollout years])
        var _year=EDATE(MIN('Table'[date1]),_addY*12)
        return _year

        result

         

        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.