CURRENT MONTH IN D365:
When we are calculating the total amount is equal to the current month then following these steps.
Steps:-
1.Go to PowerApps in advance settings create a new web resource
2.In that web resource we can add the java script code in text editor then save and publish
- Go to main form and add the form properties in form libraries on web resource.
4.In event handlers add the function name and the event name on ON-change event then save and publish
- Play your app and enter the data then check the output
Java Script Code:-
function TotalcurrentmonthAmount(executionContext) {
formContext = executionContext.getFormContext();
var totalmtd = 0;
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const month = [“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”];
const d = new Date();
currentmonth = d.getMonth();
var crmonth = month[currentmonth];
var apiContext = (typeof Xrm !== “undefined”) ? Xrm : parent.Xrm;
apiContext.WebApi.retrieveMultipleRecords(“vijay_budget”, “?$select=vijay_amount,vijay_month,vijay_totalmtd,vijay_year”).then(
function success(results) {
console.log(results);
for (var i = 0; i < results.entities.length; i++) {
var result = results.entities[i];
// Columns
var vijay_budgetid = result[“vijay_budgetid”]; // Guid
var vijay_amount = result[“vijay_amount”]; // Whole Number
var vijay_amount_formatted = result[“vijay_amount@OData.Community.Display.V1.FormattedValue”];
var vijay_month = result[“vijay_month”]; // Text
var vijay_year = result[“vijay_year”];
var vijay_totalmtd = result[“vijay_totalmtd”]; // Whole Number
var vijay_totalmtd_formatted = result[“vijay_totalmtd@OData.Community.Display.V1.FormattedValue”];
if ( vijay_year == currentYear, vijay_month == crmonth) {
totalmtd += vijay_amount;
}
}
console.log(“Total MTD: ” + totalmtd);
formContext.getAttribute(“vijay_totalmtd”).setValue(totalmtd );
},
function(error) {
console.log(error.message);
}
);
}
When the current year and current month is equal your data in fields that time you will get the correct output see like this
*When the current year and current month is equal your data

*When the Current Year and Current Amount

*Here the total amount should be populated on every YEAR is equal

*Here the total amount should be populated on every month is equal

For any Help or Queries Contact us on info@crmonce.com or +91 8096556344
https://www.crmonce.com/field-parameter-in-power-bi-desktop/