Forum Discussion

shivamsharma1's avatar
shivamsharma1
Regular Visitor
4 years ago
Solved

How to add/subtract hours from date using parameter?

I have a CreationDate column and i want to create another column where i can add/subtract hours using a parameter. For eg

CreationDate = 21 Jan 2022, 2 PM and Parameter = 2, the value would be 21 Jan 2022, 2 PM + 2 = 21 Jan 2022, $ PM

Similarly if Parameter = -3, the new column would be 21 Jan 2022, 2 PM - 3 = 21 Jan 2022, 11 AM

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi shivamsharma1 ,

     

    Since the new date is dynamically changed by parameter, you need to create Measure instead of Calculated Column. (Column is static that could not be changed )

     

    Please firstly add a What-if parameter 

    And then create measure:

    New Date Measure = MAX('Table'[CreationDate ]) +(1/24) *[Parameter Value]

    Output:

     

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi shivamsharma1 ,

     

    Since the new date is dynamically changed by parameter, you need to create Measure instead of Calculated Column. (Column is static that could not be changed )

     

    Please firstly add a What-if parameter 

    And then create measure:

    New Date Measure = MAX('Table'[CreationDate ]) +(1/24) *[Parameter Value]

    Output:

     

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    Not applicable

    If your parameter is named AddHours, your custom column formula would be:

     

    = Table.AddColumn(PriorStepOrTableName, "Adjusted", each [Created Date] + #duration(0, AddHours, 0, 0))

     

    --Nate

  • Hey Anonymous,

     

    thanks for replying but I wanted to use this computation in dax rather thatn using in M query. Because my columns have dates from 3 different columns