Forum Discussion
convert excel formula to powerbi function - calc start date from end date - duration (D/W/M/Y)
- 7 years ago
Thank you for replying... I figure out a way first using the DAX side then I went back to the power query editor and created a function to add the new column with the desired results. Going back and forth between syntax is keeping me on my toes.
Below is the function I created that is working.
let StartUpgradeDate = (DurTime,DurCnt,UpgradeRpDate) => if DurTime="day" or DurTime="days" then
Date.AddDays(UpgradeRpDate, (DurCnt*-1))
else if DurTime="week" or DurTime="weeks" then
Date.AddWeeks(UpgradeRpDate, (DurCnt*-1))
else if DurTime="month" or DurTime="months" then
Date.AddMonths(UpgradeRpDate, (DurCnt*-1))
else if DurTime="year" or DurTime="years" then
Date.AddYears(UpgradeRpDate, (DurCnt*-1))
else ""
in StartUpgradeDate
In DAX, LOOKUPVALUE() is similar to VLOOPUP(), in addtion, I haven't found any reference about CALCWEEK(), CALCMONTH() and CALCYEAR(), however, you may refer to the time intelligence functions here.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for replying... I figure out a way first using the DAX side then I went back to the power query editor and created a function to add the new column with the desired results. Going back and forth between syntax is keeping me on my toes.
Below is the function I created that is working.
let StartUpgradeDate = (DurTime,DurCnt,UpgradeRpDate) => if DurTime="day" or DurTime="days" then
Date.AddDays(UpgradeRpDate, (DurCnt*-1))
else if DurTime="week" or DurTime="weeks" then
Date.AddWeeks(UpgradeRpDate, (DurCnt*-1))
else if DurTime="month" or DurTime="months" then
Date.AddMonths(UpgradeRpDate, (DurCnt*-1))
else if DurTime="year" or DurTime="years" then
Date.AddYears(UpgradeRpDate, (DurCnt*-1))
else ""
in StartUpgradeDate