<?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: [DAX] Counting consecutive days of an event in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493390#M28745</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please find the file here -&amp;nbsp;&lt;A href="http://s000.tinyupload.com/index.php?file_id=03701814126592699638" target="_blank" rel="noopener"&gt;TABLE1&lt;/A&gt;&amp;nbsp;(fact journey)&amp;nbsp;&lt;A href="http://s000.tinyupload.com/index.php?file_id=20959358412736766259" target="_blank" rel="noopener"&gt;TABLE2&lt;/A&gt;&amp;nbsp; (dim vehicles)&lt;BR /&gt;&lt;BR /&gt;Inactive day will be considered any day that there is no journey ID for the vehicle.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The dashboard has a date filter, so the client can check the how many days the vehicle has not worked in the last semester or in the last week. We can start counting from the first date registered on the table. It will be date one.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am not sure if it is possible yet.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tryed to create a crossjoin table to summarize all vehicles and dates possibilities:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TESTE = 
    CROSSJOIN(SELECTCOLUMNS('corteva dim_vehicles',"Vehicle_id",'corteva dim_vehicles'[vehicle_id]),DISTINCT('corteva fact_journeys'[Data]))&lt;/LI-CODE&gt;&lt;P&gt;And counted the number of journeys that the vehicles has done in that day:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Journeys = CALCULATE(DISTINCTCOUNT('corteva fact_journeys'[journey_id]), FILTER('corteva fact_journeys','corteva fact_journeys'[vehicle_id]=TESTE[Vehicle_id]),FILTER('corteva fact_journeys','corteva fact_journeys'[Data]=TESTE[Data]))&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The wanted output is something like that:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;I hope I was able to explain it better.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Nov 2020 17:36:00 GMT</pubDate>
    <dc:creator>DDalmas</dc:creator>
    <dc:date>2020-11-13T17:36:00Z</dc:date>
    <item>
      <title>[DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1491010#M28659</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have to count the maximum of consecutive days that a vehicle has worked.&amp;nbsp;&lt;BR /&gt;The fact table contains the vehicle_ID, the date and the journey_id.&amp;nbsp;&lt;BR /&gt;Journey_id is the register of the every single time the driver turns on the vehicle. It can happen many times during the day.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Is it possible?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 18:27:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1491010#M28659</guid>
      <dc:creator>DDalmas</dc:creator>
      <dc:date>2020-11-12T18:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1491158#M28665</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92133" data-lia-user-login="DDalmas" class="lia-mention lia-mention-user"&gt;DDalmas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please &lt;STRONG&gt;always&lt;/STRONG&gt; show your sample data in &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;text-tabular format&lt;/FONT&gt;&lt;/STRONG&gt; in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1.&lt;/STRONG&gt; Place Vehicle_Id in a table visual&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2.&lt;/STRONG&gt; Create this measure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max per vehicle = 
VAR summT_ =
    SUMMARIZE ( Table1, Table1[Vehicle_ID], Table1[Date] )
VAR auxT_ =
    FILTER (
        ADDCOLUMNS (
            summT_,
            "index_",
                COUNTROWS ( FILTER ( summT_, [Date] &amp;lt;= EARLIER ( [Date] ) ) ) 
        ),
        VAR nextDate_ =
            MINX ( FILTER ( summT_, [Date] &amp;gt; EARLIER ( [Date] ) ), [Date] )
        RETURN
             ( nextDate_ - [Date] ) &amp;lt;&amp;gt; 1
    )
VAR res_ =
    MAXX (
        auxT_,
        [index_] - MAXX ( FILTER ( auxT_, [index_] &amp;lt; EARLIER ( [index_] ) ), [index_] )
    )
RETURN
    res_&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;. Create this other measure that uses the previous one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max of Max per vehicle = 
MAXX ( DISTINCT ( Table1[Vehicle_ID] ), [Max per vehicle] )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;4&lt;/STRONG&gt;. Place [Max of Max per vehicle] in the visual to see the&amp;nbsp; maximum number of consecutive days&amp;nbsp;per vehicle and the total (i.e the max of the max per vehicle). You can also place this measure in a card visual to see only the max of the max&amp;nbsp; (for all vehicles)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;5.&lt;/STRONG&gt; See it all at work in the attached file with a very simplified fact table&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving a thumbs up if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs, tutoring, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 08:21:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1491158#M28665</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-11-13T08:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1491299#M28668</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92178" data-lia-user-login="AlB" class="lia-mention lia-mention-user"&gt;AlB&lt;/a&gt;&amp;nbsp;Thank you very much for this idea. I will be trying to do it tomorrow.&lt;BR /&gt;&lt;BR /&gt;I am new here, sorry for the print screen. Next time, I will attach the pbix.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 22:44:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1491299#M28668</guid>
      <dc:creator>DDalmas</dc:creator>
      <dc:date>2020-11-12T22:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493087#M28721</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92178" data-lia-user-login="AlB" class="lia-mention lia-mention-user"&gt;AlB&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've tryed to do it, but it does not seems to work properly.&amp;nbsp;&lt;BR /&gt;Maybe, I haven't explained very well. I have to display in a table with all vehicles, a colum containing the maximum number of day that every single vehicle has not worked.&amp;nbsp;&lt;BR /&gt;Maybe the measure has to count the consecutive blank days, because I did the croossjoin between all vehicles_ids and all possible dates. I don't know if it will work.&amp;nbsp;&lt;BR /&gt;I will attach a sample of the original table from the datawarehouse. It contains the last 10 days.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;A title="table1" href="https://docs.google.com/spreadsheets/d/1sJYZg8YOhyqdeReAhzNntoNXEE_wXiouhVAYvpo4hXY/edit?usp=sharing" target="_blank" rel="noopener"&gt;table1&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks for your help, again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 14:45:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493087#M28721</guid>
      <dc:creator>DDalmas</dc:creator>
      <dc:date>2020-11-13T14:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493219#M28731</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92133" data-lia-user-login="DDalmas" class="lia-mention lia-mention-user"&gt;DDalmas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot access the link. Seems to require a sign in with a Google account. Either remove that requirement or post it elsewhere (Dropbox, tinyupload.com, etc)&lt;/P&gt;
&lt;P&gt;You explained exactly the opposite on your initial posting:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I have to count the maximum of consecutive days that a vehicle&lt;STRONG&gt; has worked.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd need a more detailed, accurate explanation before maknig another attempt. You talk about inactive days. What will be considered inactive days in your data? Is this on a specific period of time? For instance, if a vehicle has data on these dates (MM/DD/Year):&lt;/P&gt;
&lt;P&gt;01/01/2019&lt;/P&gt;
&lt;P&gt;01/02/2019&lt;/P&gt;
&lt;P&gt;01/04/2019&lt;/P&gt;
&lt;P&gt;01/06/2019 &amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many inactive days is that? Do we count any inactive day before 01/01/2019 or after 01/06/2019? How?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving a thumbs up if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs, tutoring, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&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;</description>
      <pubDate>Fri, 13 Nov 2020 16:05:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493219#M28731</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-11-13T16:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493390#M28745</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please find the file here -&amp;nbsp;&lt;A href="http://s000.tinyupload.com/index.php?file_id=03701814126592699638" target="_blank" rel="noopener"&gt;TABLE1&lt;/A&gt;&amp;nbsp;(fact journey)&amp;nbsp;&lt;A href="http://s000.tinyupload.com/index.php?file_id=20959358412736766259" target="_blank" rel="noopener"&gt;TABLE2&lt;/A&gt;&amp;nbsp; (dim vehicles)&lt;BR /&gt;&lt;BR /&gt;Inactive day will be considered any day that there is no journey ID for the vehicle.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The dashboard has a date filter, so the client can check the how many days the vehicle has not worked in the last semester or in the last week. We can start counting from the first date registered on the table. It will be date one.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am not sure if it is possible yet.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tryed to create a crossjoin table to summarize all vehicles and dates possibilities:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TESTE = 
    CROSSJOIN(SELECTCOLUMNS('corteva dim_vehicles',"Vehicle_id",'corteva dim_vehicles'[vehicle_id]),DISTINCT('corteva fact_journeys'[Data]))&lt;/LI-CODE&gt;&lt;P&gt;And counted the number of journeys that the vehicles has done in that day:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Journeys = CALCULATE(DISTINCTCOUNT('corteva fact_journeys'[journey_id]), FILTER('corteva fact_journeys','corteva fact_journeys'[vehicle_id]=TESTE[Vehicle_id]),FILTER('corteva fact_journeys','corteva fact_journeys'[Data]=TESTE[Data]))&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The wanted output is something like that:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;I hope I was able to explain it better.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 17:36:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493390#M28745</guid>
      <dc:creator>DDalmas</dc:creator>
      <dc:date>2020-11-13T17:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Counting consecutive days of an event</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493446#M28747</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92133" data-lia-user-login="DDalmas" class="lia-mention lia-mention-user"&gt;DDalmas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following a similar approach to earlier&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1.&lt;/STRONG&gt; Place Vehicle_Id in a table visual&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2.&lt;/STRONG&gt; Create this measure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max number Inactive Days per vehicle = 
    VAR summT0_ = DISTINCT( Table1[Date] )
    VAR allDatesInPeriod_ = SELECTCOLUMNS(GENERATESERIES(MIN(Table1[Date]), MAX(Table1[Date])), "Date",[Value])
    VAR summT_ = EXCEPT(allDatesInPeriod_,summT0_)
    VAR auxT_ =
        FILTER (
            ADDCOLUMNS (
                summT_,
                "index_",
                    COUNTROWS ( FILTER ( summT_, [Date] &amp;lt;= EARLIER ( [Date] ) ) ) 
            ),
            VAR nextDate_ =
                MINX ( FILTER ( summT_, [Date] &amp;gt; EARLIER ( [Date] ) ), [Date] )
            RETURN
                 ( nextDate_ - [Date] ) &amp;lt;&amp;gt; 1
        )
    VAR res_ =
        MAXX (
            auxT_,
            [index_]
                - MAXX ( FILTER ( auxT_, [index_] &amp;lt; EARLIER ( [index_] ) ), [index_] )
        )
    RETURN
         res_&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;. Create this other measure that uses the previous one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max number Inactive Days per vehicle TOT = 
MAXX ( DISTINCT ( Table1[Vehicle_ID] ), [Max number Inactive Days per vehicle] )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;. Place [Max number Inactive Days per vehicle TOT] in the visual to see the maximum number of consecutive INACTIVE days&amp;nbsp;per vehicle and the total (i.e the max of the max per vehicle). You can also place this measure in a card visual to see only the max of the max&amp;nbsp; (for all vehicles)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;5.&lt;/STRONG&gt; &lt;STRONG&gt;See it all at work in the attached file with a very simplified fact table&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please mark the question solved when done and consider &lt;FONT color="#FF9900"&gt;giving a thumbs up if posts are helpful.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Contact me privately for support with any larger-scale BI needs, tutoring, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers&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;</description>
      <pubDate>Fri, 13 Nov 2020 18:11:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Counting-consecutive-days-of-an-event/m-p/1493446#M28747</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2020-11-13T18:11:33Z</dc:date>
    </item>
  </channel>
</rss>

