<?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: Count Open Orders with missing date records in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500281#M69114</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="353745" data-lia-user-login="tackytechtom" class="lia-mention lia-mention-user"&gt;tackytechtom&lt;/a&gt;&amp;nbsp;: Thanks you so much! Could you please share your PBI File?&lt;/P&gt;</description>
    <pubDate>Sun, 08 May 2022 16:12:27 GMT</pubDate>
    <dc:creator>joshua1990</dc:creator>
    <dc:date>2022-05-08T16:12:27Z</dc:date>
    <item>
      <title>Count Open Orders with missing date records</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500258#M69112</link>
      <description>&lt;P&gt;Hi community!&lt;/P&gt;&lt;P&gt;I have a pretty simple table that shows me all status changes for each order:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Order Nr&lt;/TD&gt;&lt;TD&gt;Status&lt;/TD&gt;&lt;TD&gt;Status Changed Date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;555&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01.01.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;555&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;05.01.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;555&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;15.01.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;556&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;05.01.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;556&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;20.01.2021&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see there is just a record if a status was changed.&lt;/P&gt;&lt;P&gt;Now I would like to display on a bar chart every day of the current year with number of Orders with a Status &amp;lt;&amp;gt; 'C'.&lt;/P&gt;&lt;P&gt;Bow how?&lt;/P&gt;&lt;P&gt;A simple CALCULATE(DISTINCOUNT(Orders[Orders]), Status &amp;lt;&amp;gt; 'C') will not work since there are no records for each day.&lt;/P&gt;&lt;P&gt;How can this be solved using DAX?&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 14:27:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500258#M69112</guid>
      <dc:creator>joshua1990</dc:creator>
      <dc:date>2022-05-08T14:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count Open Orders with missing date records</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500271#M69113</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe something like this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The secret is to "unfold" / "expand" the dates in between the status changes. So instead of having your table, I would try to change the grain and get something like this one (just for the Order Nr = 555):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With such a table, Power BI / DAX will have it easy to display the Number of Orders per day (just create a measure with a filter on status &amp;lt;&amp;gt; "c" ) I did the transformation in PQ, where I first created an additional date column which is a bit like an "End Date". With a StartDate and EndDate column grouped by OrderNr it is pretty easy to create the rows between them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the code for the advanced editor. Note, my table is called&amp;nbsp;FillRowsBetweenDates.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjU1VdJRcgRiA0M9IDIyMDJUitWBSTiBJEyxSDgDsSG6hBnMKGwSIB1GBgiJWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order Nr" = _t, Status = _t, #"Status Changed Date" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Order Nr"}, {{"Grouping", each _, type table [Order Nr=nullable number, Status=nullable text, Status Changed Date=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ( [Grouping], "Index", 1 )),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Order Nr", "Status", "Status Changed Date", "Index"}, {"Order Nr", "Status", "Status Changed Date", "Index"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "JoinIndex", each [Index] - 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Custom1", {"Order Nr", "Index"}, #"Added Custom1", {"Order Nr", "JoinIndex"}, "Added Custom1", JoinKind.LeftOuter),
    #"Renamed Columns" = Table.RenameColumns(#"Merged Queries",{{"Status Changed Date", "Start Date"}}),
    #"Expanded Added Custom1" = Table.ExpandTableColumn(#"Renamed Columns", "Added Custom1", {"Status Changed Date"}, {"Status Changed Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Added Custom1",{"Index", "JoinIndex"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Order Nr", Int64.Type}, {"Status", type text}, {"Start Date", type date}, {"Status Changed Date", type date}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type", "Custom", each if [Status Changed Date] = null then null else { Number.From ( [Start Date] ) ..Number.From ( [Status Changed Date] ) -1 }),
    #"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom2", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom1",{{"Custom", type date}})
in
    #"Changed Type1"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this helps or if you get stuck somewhere &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Tom&lt;BR /&gt;&lt;A href="https://www.tackytech.blog/" target="_blank" rel="noopener"&gt;https://www.tackytech.blog/&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.instagram.com/tackytechtom/" target="_blank" rel="noopener"&gt;https://www.instagram.com/tackytechtom/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 15:28:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500271#M69113</guid>
      <dc:creator>tackytechtom</dc:creator>
      <dc:date>2022-05-08T15:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count Open Orders with missing date records</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500281#M69114</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="353745" data-lia-user-login="tackytechtom" class="lia-mention lia-mention-user"&gt;tackytechtom&lt;/a&gt;&amp;nbsp;: Thanks you so much! Could you please share your PBI File?&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 16:12:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500281#M69114</guid>
      <dc:creator>joshua1990</dc:creator>
      <dc:date>2022-05-08T16:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count Open Orders with missing date records</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500308#M69115</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/s/jz5pk5lhl4d5tn9/FillRowsBetweenDates.pbix?dl=0" target="_blank"&gt;https://www.dropbox.com/s/jz5pk5lhl4d5tn9/FillRowsBetweenDates.pbix?dl=0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Tom&lt;BR /&gt;&lt;A href="https://www.tackytech.blog/" target="_blank"&gt;https://www.tackytech.blog/&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.instagram.com/tackytechtom/" target="_blank"&gt;https://www.instagram.com/tackytechtom/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 17:47:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500308#M69115</guid>
      <dc:creator>tackytechtom</dc:creator>
      <dc:date>2022-05-08T17:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count Open Orders with missing date records</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500358#M69118</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;If Power query is not an option then another way of doing that using DAX only (must have a date table with or without relationship):&amp;nbsp;&lt;A href="https://www.dropbox.com/t/e3B2ky5BjspDINnw" target="_blank"&gt;https://www.dropbox.com/t/e3B2ky5BjspDINnw&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Number of Orders = 
VAR CurrentDate = MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUMX (
            VALUES ( Orders[Order Nr] ),
            VAR ActiveOrdersTable =
                CALCULATETABLE (
                    Orders,
                    Orders[Status Changed Date] &amp;lt;= CurrentDate
                )
            VAR StatusCTable =
                FILTER ( ActiveOrdersTable, Orders[Status] = "C" )
            RETURN
            IF (
                COUNTROWS ( ActiveOrdersTable ) &amp;gt; 0 &amp;amp;&amp;amp; COUNTROWS ( StatusCTable ) = 0,
                1
            )
        ),
        REMOVEFILTERS ( 'Date' )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 19:09:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2500358#M69118</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-05-08T19:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count Open Orders with missing date records</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2506195#M69407</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Has your problem been solved, if so, you can mark its correct answer as a mark, if not, provide details and we can help you better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 02:26:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Open-Orders-with-missing-date-records/m-p/2506195#M69407</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-11T02:26:27Z</dc:date>
    </item>
  </channel>
</rss>

