Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
shivamsharma1
Regular Visitor

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

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

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 

Eyelyn9_0-1646114946367.png

And then create measure:

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

Output:

Eyelyn9_1-1646114974455.png Eyelyn9_2-1646114996515.png

 

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.

View solution in original post

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

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 

Eyelyn9_0-1646114946367.png

And then create measure:

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

Output:

Eyelyn9_1-1646114974455.png Eyelyn9_2-1646114996515.png

 

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.

Thank you @v-eqin-msft . This worked

shivamsharma1
Regular Visitor

Hey @watkinnc,

 

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

watkinnc
Super User
Super User

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


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors