<?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: Limit interval in iterator to next sale - with dax.do example in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2641529#M77568</link>
    <description>&lt;LI-CODE lang="markup"&gt;SUMX (
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( 'Movements', 'Movements'[Item], 'Filter Date'[Date] ),
            "nextMovement",
                VAR Day = 'Filter Date'[Date]
                RETURN
                    LOOKUPVALUE (
                        'Filter Date'[Date],
                        'Filter Date'[DateKey], CALCULATE ( MIN ( 'Movements'[DateKey] ), 'Filter Date'[Date] &amp;gt; Day )
                    )
        ),
        'Filter MovementCodes'[Number] IN { "1314" }
    ),
    VAR MinDay =
        CALCULATE ( MIN ( 'Filter Date'[Date] ) ) + 1
    VAR MaxDay =
        MIN (
            MinDay + 14,
            IF ( ISBLANK ( [nextMovement] ), MinDay + 14, [nextMovement] )
        )
    RETURN
        CALCULATE (
            [Movement Qty],
            'Filter MovementCodes'[Number] = "77777",
            DATESBETWEEN ( 'Filter Date'[Date], MinDay, MaxDay ),
            ALL ( 'Filter Date' )
        )
)&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 15 Jul 2022 14:04:04 GMT</pubDate>
    <dc:creator>rks</dc:creator>
    <dc:date>2022-07-15T14:04:04Z</dc:date>
    <item>
      <title>Limit interval in iterator to next sale - with dax.do example</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2639124#M77450</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a measure (see below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;VAR Iterator =
        CALCULATETABLE(
            SUMMARIZE(
                'Movements',
                'Movements'[ItemId],
                'Filter Date'[Day]
            ),
            'Filter Movement Code'[Number] = 2
        )
RETURN
    SUMX(
        Iterator,
        VAR MinTag = CALCULATE( MIN( 'Filter Date'[Day] ) )
        RETURN
            CALCULATE(
                [Sum of Movements],
                'Filter Movement Code'[Number] = 235,
                DATESBETWEEN( 'Filter Date'[Day], MinTag, MinTag + 14 ),
                ALL( 'Filter Date' )
            )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This measure iterates over items moved on a given day for a certain reason. For those items I want sum the quantity (sum of movements) with another reason 14 days after the initial movement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if the same item has been moved again with reason 2 within 14 days, I want to decrease the relevant date-interval from the initial movement (no =&amp;nbsp; 2) until the next movement (no = 2). So basically it's either 14 days if there's no subsequent movement or the number of days between first movement and next movement (of no = 2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to adapt the problem:&lt;/P&gt;&lt;P&gt;&lt;A href="https://dax.do/tMtgqnPYWGBrjT/" target="_blank"&gt;https://dax.do/tMtgqnPYWGBrjT/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What products where sold in&amp;nbsp;Rockhampton and have been sold within the next two weeks in&amp;nbsp;Seaford. However, if the same product was sold twice within 14 days in&amp;nbsp;Rockhampton the interval shouldn't be 14 days but the number of days between the two sales.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Konstantin&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 14:37:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2639124#M77450</guid>
      <dc:creator>rks</dc:creator>
      <dc:date>2022-07-14T14:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Limit interval in iterator to next sale - with dax.do example</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2639286#M77459</link>
      <description>&lt;P&gt;Try&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;DEFINE
    MEASURE 'Sales'[Problem] =
        VAR Iterator =
            CALCULATETABLE (
                ADDCOLUMNS (
                    SUMMARIZE ( 'Sales', Sales[ProductKey], 'Date'[Date] ),
                    "next sale date",
                    CALCULATE(MIN( Sales[Order Date]), Sales[Order Date] &amp;gt; SELECTEDVALUE ('Date'[Date]))
                ),
                Customer[City] = "Rockhampton"
            )
        RETURN
            SUMX (
                Iterator,
                VAR MinTag =
                    CALCULATE ( MIN ( 'Date'[Date] ) )
                VAR MaxTag = MIN( MinTag + 14, [next sale date])
                RETURN
                    CALCULATE (
                        [Sales Amount],
                        Customer[City] = "Seaford",
                        DATESBETWEEN ( 'Date'[Date], MinTag, MaxTag ),
                        ALL ( 'Date' )
                    )
            )

EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Calendar Year Month],
    "Qty", [Sales Amount],
    "Qty2", [Problem]
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Jul 2022 15:58:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2639286#M77459</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-07-14T15:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Limit interval in iterator to next sale - with dax.do example</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2640312#M77498</link>
      <description>&lt;P&gt;Hi John, thank you for the answer.&lt;/P&gt;&lt;P&gt;When running the code in dax.do I receive a valid result. However, my model (hosted on PPU) has got a different opinion. I receive this error message:&lt;/P&gt;&lt;P&gt;The column "next sale date" does not exist or cannot be used in this expression.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like I cannot access the columns from the "iterator"?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 06:14:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2640312#M77498</guid>
      <dc:creator>rks</dc:creator>
      <dc:date>2022-07-15T06:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Limit interval in iterator to next sale - with dax.do example</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2640754#M77517</link>
      <description>&lt;P&gt;Are you sure that there are no typos in either of the names and that they are both the same?&lt;/P&gt;&lt;P&gt;The SUMX gives you a row context on Iterator, so you should be able to access any of the columns in that table, even though it is a variable.&lt;/P&gt;&lt;P&gt;The only other thing I can think to try is to run the CALCULATETABLE statement in DAX Studio and check the table it comes back with&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 08:48:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2640754#M77517</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-07-15T08:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Limit interval in iterator to next sale - with dax.do example</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2641529#M77568</link>
      <description>&lt;LI-CODE lang="markup"&gt;SUMX (
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( 'Movements', 'Movements'[Item], 'Filter Date'[Date] ),
            "nextMovement",
                VAR Day = 'Filter Date'[Date]
                RETURN
                    LOOKUPVALUE (
                        'Filter Date'[Date],
                        'Filter Date'[DateKey], CALCULATE ( MIN ( 'Movements'[DateKey] ), 'Filter Date'[Date] &amp;gt; Day )
                    )
        ),
        'Filter MovementCodes'[Number] IN { "1314" }
    ),
    VAR MinDay =
        CALCULATE ( MIN ( 'Filter Date'[Date] ) ) + 1
    VAR MaxDay =
        MIN (
            MinDay + 14,
            IF ( ISBLANK ( [nextMovement] ), MinDay + 14, [nextMovement] )
        )
    RETURN
        CALCULATE (
            [Movement Qty],
            'Filter MovementCodes'[Number] = "77777",
            DATESBETWEEN ( 'Filter Date'[Date], MinDay, MaxDay ),
            ALL ( 'Filter Date' )
        )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 15 Jul 2022 14:04:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Limit-interval-in-iterator-to-next-sale-with-dax-do-example/m-p/2641529#M77568</guid>
      <dc:creator>rks</dc:creator>
      <dc:date>2022-07-15T14:04:04Z</dc:date>
    </item>
  </channel>
</rss>

