<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Transforming Data with M in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1941192#M57230</link>
    <description>&lt;P&gt;Here's one way to do it in the query editor.&amp;nbsp;&amp;nbsp;To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.&amp;nbsp; Did you mean to do + Exit - Entrance, since the End date is before the Start date with the formula above?&amp;nbsp; You can adapt this, if so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wyk8u0TcyUNJRMgURZgZKsTrRSnn5ZRBBCxBhaAQRTUlNhogawZTGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Entrance = _t, Exit = _t]),
    #"Added Custom" = Table.AddColumn(Source, "DateForCalc", each "1/"&amp;amp;[Date]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Entrance", Int64.Type}, {"Exit", Int64.Type}, {"DateForCalc", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Start", each Date.EndOfMonth(Date.AddMonths([DateForCalc], -1)), type date),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "End", each Date.AddDays([Start], [Entrance] - [Exit]), type date)
in
    #"Added Custom2"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jul 2021 21:24:54 GMT</pubDate>
    <dc:creator>mahoneypat</dc:creator>
    <dc:date>2021-07-06T21:24:54Z</dc:date>
    <item>
      <title>Transforming Data with M</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1940921#M57227</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;I have a table data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need create two more columns like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;and fill in the &lt;STRONG&gt;START&lt;/STRONG&gt; and &lt;STRONG&gt;END&lt;/STRONG&gt; columns following the formula:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;START = END OF PREVIOUS MONTH (in this case the month of september)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;END = (START + ENTRANCE) - EXIT&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dates are varied, they can comprise several periods according to the user's parameter date filter. I always have the START number for the first month given through a "STARTDATE" measure DAX.&lt;/P&gt;&lt;P&gt;I imagine the path is to do in M, can you give me a light?&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 20:39:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1940921#M57227</guid>
      <dc:creator>credencial</dc:creator>
      <dc:date>2021-07-06T20:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming Data with M</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1941192#M57230</link>
      <description>&lt;P&gt;Here's one way to do it in the query editor.&amp;nbsp;&amp;nbsp;To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.&amp;nbsp; Did you mean to do + Exit - Entrance, since the End date is before the Start date with the formula above?&amp;nbsp; You can adapt this, if so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wyk8u0TcyUNJRMgURZgZKsTrRSnn5ZRBBCxBhaAQRTUlNhogawZTGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Entrance = _t, Exit = _t]),
    #"Added Custom" = Table.AddColumn(Source, "DateForCalc", each "1/"&amp;amp;[Date]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Entrance", Int64.Type}, {"Exit", Int64.Type}, {"DateForCalc", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Start", each Date.EndOfMonth(Date.AddMonths([DateForCalc], -1)), type date),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "End", each Date.AddDays([Start], [Entrance] - [Exit]), type date)
in
    #"Added Custom2"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 21:24:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1941192#M57230</guid>
      <dc:creator>mahoneypat</dc:creator>
      <dc:date>2021-07-06T21:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming Data with M</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1941419#M57232</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="226208" data-lia-user-login="mahoneypat" class="lia-mention lia-mention-user"&gt;mahoneypat&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested your suggestion, but I didn't get the result. Maybe I didn't explain it right. I need this result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 01:37:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1941419#M57232</guid>
      <dc:creator>credencial</dc:creator>
      <dc:date>2021-07-07T01:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming Data with M</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1947884#M57404</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="311739" data-lia-user-login="credencial" class="lia-mention lia-mention-user"&gt;credencial&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the whole M syntax:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKk4t0DcyUNJRgiBDAwOlWJ1opfzkEoiwKYgwAysAiefll0HELUCEoRFcIiU1GSJhhKQhFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Entrance = _t, Exit = _t, End = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Entrance", Int64.Type}, {"Exit", Int64.Type}, {"End", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each try #"Added Index" [End] {[Index] - 1} otherwise null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"End"}),
    #"Added Custom1" = Table.AddColumn(#"Filled Down", "Custom.1", each if [Index]=0 then [End] else [End]+List.Sum(List.Range(#"Filled Down"[Entrance],1,[Index]))-List.Sum(List.Range(#"Filled Down"[Exit],1,[Index]))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"}),
    #"Added Custom2" = Table.AddColumn(#"Removed Columns", "Custom", each try #"Added Custom1" [Custom.1]{[Index] - 1} otherwise null),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom2",{"Index", "End"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Custom.1", "End"}, {"Custom", "Start"}})
in
    #"Renamed Columns"&lt;/LI-CODE&gt;
&lt;P&gt;The final result is this.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Stephen Tao&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&lt;STRONG&gt;&lt;EM&gt; Accept it as the solution &lt;/EM&gt;&lt;/STRONG&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:41:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1947884#M57404</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-07-09T09:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming Data with M</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1948031#M57408</link>
      <description>&lt;P&gt;Thanks for solution&amp;nbsp;Anonymous&lt;/a&gt;. Perfect.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 11:14:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Transforming-Data-with-M/m-p/1948031#M57408</guid>
      <dc:creator>credencial</dc:creator>
      <dc:date>2021-07-09T11:14:07Z</dc:date>
    </item>
  </channel>
</rss>

