Forum Discussion
I need Help With A Date Formula
You have to prepare your real data to same state as you have you sample in excel. Then just edit Source step of my query and refer your query name with real data (you can check it again in note below, but read carefully)
Hello dufoq3, sorry it took me this long to get back to you yesterday I finally got the code working and sorted the problems I had with the source as you can tell I was new to Power Query and didn't know anything about it or how does it work, so the code works perfectly now and I'm sorry but I need one more thing, as you know this code only works with "Won" deals but could you make it that it would work for "Lost" also? the code is below and before you go to it I just wanted to let you know that I changed the "Deal Stage" in the code to the orginal value so in this case the "Deal Stage" is "alfa_roadmapstatus" I thgout it would be beter if I coded from the source not from the custom columns so in this case "Won" = 6 and "Lost" = 8 here is the code
Source = OData.Feed(My Data Source, null, [Implementation="2.0"]),
opportunities_table = Source{[Name="opportunities",Signature="table"]}[Data],
TrimmedColumnNames = Table.TransformColumnNames(opportunities_table, Text.Trim),
ChangedType = Table.TransformColumnTypes(TrimmedColumnNames, {
{"estimatedclosedate", type date}, {"actualclosedate", type date}
}),
Ad_EstCloseYear = Table.AddColumn(ChangedType, "Est Close Year", each Date.Year([estimatedclosedate]), Int64.Type),
Ad_CloseYear = Table.AddColumn(Ad_EstCloseYear, "Close Year", each Date.Year([actualclosedate]), Int64.Type),
Ad_NewCloseDate = Table.AddColumn(Ad_CloseYear, "New Close Date", each
let
today = Date.From(DateTime.FixedLocalNow())
in
if [alfa_roadmapstatus] <> 6 then null else
if [actualclosedate] = null and [estimatedclosedate] <> null and [estimatedclosedate] > today then today else
if [actualclosedate] = null and [estimatedclosedate] <> null then [estimatedclosedate] else
if [actualclosedate] <> null and [Close Year] > [Est Close Year] then [estimatedclosedate] else
[actualclosedate]
, type date),