Forum Discussion
I need Help With A Date Formula
I uploaded the Excel file but I have a question my real data is connected through Daynimc 365 online dose that make a difference?
I've edited my previous post few seconds ago - read it please.
- mohammedald2 years agoHelper I
Ok now it works in the sample but the main data still have issues I don't know if it's because the connection is online and I don't have the data in a local folder, I will start a fresh connection and try it again
- dufoq32 years agoCommunity Champion
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)
- mohammedald2 years agoHelper I
I don't know much about coding in power query but couldn't we just write a code that fits in a custom column without all that source stuff?
- mohammedald2 years agoHelper I
Ok I started a new connection and I loaded it through Dynamic 365 Online and then I clicked transform data and went straight to Advanced Editor and this showed up
let
Source = OData.Feed(There is a link here to the CRM Conection, null, [Implementation="2.0"]),
opportunities_table = Source{[Name="opportunities",Signature="table"]}[Data]
in
opportunities_table
where can I find my source is it all of it ?
- mohammedald2 years agoHelper I
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),