cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chachaK
New Member

Month to Date Computation

Would like to know how to implement the following computation field in my portal.

MTD = (cumulativeSales/DIFFINDAYS( Now()-startMonthDate))*TotalMonthdays.

 

The challenge is obtaining the startMonthDate from the CurrentDate and endMonthDate from the CurrentDate at any given point and time. 

Please help. 

4 REPLIES 4
OliverRodrigues
Super User
Super User

Hi, you need to populate that date field in the on create/update of a record is that your scenario?

have you looked at calculated fields? https://docs.microsoft.com/en-us/powerapps/developer/data-platform/calculated-rollup-attributes

if you need to calculate on the load of the page, you will need to apply custom JS and add your logic in there




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Thanks @OliverRodrigues  perhaps i didn't capture my requirement well in the above. 
I just need to know how to compute/Get StartofMonth  from a given date (lets say 23/04/2021) as well as EndofMonth from the same date. 

Thanks

Fubar
Solution Sage
Solution Sage

Need to be clear as to where you are needing it - i.e. is it needed in a custom Web Template = Liquid or is it just needed to when the page loads  = JavaScript

 

In JavaScript you can use the Date objects .setDate() and/or .setMonth() functions

 

// Where d = a date object
d.setDate(1) // sets the date to the first day

d.setDate(0) // sets the date to the last day of the previous month

d.setMonth(d.getMonth()+1, 1)  // sets the date to the  first day of the dates current month + 1

 

at what moment do you need to know that?




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,953)