<?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: Calculate date range when specific value is reached in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3176080#M114646</link>
    <description>&lt;P&gt;Adapted from&amp;nbsp;&lt;A href="https://www.daxpatterns.com/semi-additive-calculations/," target="_blank"&gt;https://www.daxpatterns.com/semi-additive-calculations/&lt;/A&gt;. Link your date table to the summary table, then create the below measure&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Commission under 30 =
VAR MaxCommissionDates =
    ADDCOLUMNS (
        CROSSJOIN (
            VALUES ( 'Date'[Year] ),
            SUMMARIZE ( 'Summary Table', Company[Company ID] )
        ),
        "@MaxCommissionDate", CALCULATE ( MAX ( 'Summary Table'[Date] ) )
    )
VAR MaxCommissionDatesWithLineage =
    TREATAS ( MaxCommissionDates, 'Date'[Year], Company[ID], 'Date'[Date] )
VAR Result =
    CALCULATE (
        SUMX (
            'Summary Table',
            IF (
                'Summary Table'[Commission] &amp;lt; 30,
                'Summary Table'[Commission],
                'Summary Table'[Commission] - 30
            )
        ),
        MaxCommissionDatesWithLineage
    )
RETURN
    Result
&lt;/LI-CODE&gt;
&lt;P&gt;This should work out the last date for each company in each year, then iterate over those values and subtract 30 if the commission is above 30.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Apr 2023 13:37:31 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2023-04-06T13:37:31Z</dc:date>
    <item>
      <title>Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3174358#M114538</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with a date diff calculation. I have found some similar cases in the community, but I can't seem te figure it out. I hope you can help me &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Table with companies&lt;UL&gt;&lt;LI&gt;Each company has a create date&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Table with transactions from companies&lt;UL&gt;&lt;LI&gt;Each transaction is linked to a company&lt;/LI&gt;&lt;LI&gt;Each transaction has a commission amount that belongs to the company&lt;/LI&gt;&lt;LI&gt;Each transaction has a date&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need to calculate:&lt;/P&gt;&lt;P&gt;I want to know how long it takes a company to gather €X (€75 &amp;amp; €50 &amp;amp; €30) in cumulative commission.&lt;/P&gt;&lt;P&gt;So I would need to calculate the difference between the company create date and the transaction date (of the transaction that puts the company above the €X bar).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And from all this, I would need to get the avg duration it takes a company to get to €X.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;How do I calculate the transaction date (of the transaction that puts the company above the €X bar)?&lt;/LI&gt;&lt;LI&gt;How do I calculate the date diff/duration between the create date &amp;amp; the transaction date?&lt;/LI&gt;&lt;LI&gt;How do I calculate the avg duration for all companies who have reached the €X bar?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You would make my week with a solution &lt;span class="lia-unicode-emoji" title=":upside_down_face:"&gt;🙃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anton&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 16:32:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3174358#M114538</guid>
      <dc:creator>AntonV</dc:creator>
      <dc:date>2023-04-05T16:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175522#M114618</link>
      <description>&lt;P&gt;I think that for performance reasons you will be better creating a set of calculated columns, one for each commission target, as doing the whole thing just with measures will not perform well with even a reasonable number of transactions.&lt;/P&gt;
&lt;P&gt;To start with, I would create a measure to calculate the cumulative commission earned up to a particular point in time, e.g.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Cumulative commission =
VAR MaxTransactionDate =
    MAX ( 'Transactions'[Date] )
VAR Result =
    CALCULATE (
        SUM ( 'Transactions'[Commission] ),
        REMOVEFILTERS ( 'Transactions'[Date] ),
        'Transactions'[Date] &amp;lt;= MaxTransactionDate
    )
RETURN
    Result
&lt;/LI-CODE&gt;
&lt;P&gt;And then I would create columns like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;First reached 30 =
FIRSTNONBLANK ( 'Transactions'[Date], IF ( [Cumulative commission] &amp;gt;= 30, 1 ) )
&lt;/LI-CODE&gt;
&lt;P&gt;Now that you have the values for the first dates computed you could get the average time taken with&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Avg time to 30 =
AVERAGEX (
    FILTER ( Companies, NOT ISBLANK ( Companies[First reached 30] ) ),
    DATEDIFF ( Companies[Created], Companies[First reached 30], DAY )
)
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 Apr 2023 08:45:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175522#M114618</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-04-06T08:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175856#M114630</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp; Thanks for the respons!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created the first measure (Cumulative commission).&lt;/P&gt;&lt;P&gt;Now I tried to create the calculated collumn, but I get the following error:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;How can I improve my computer memory? Or what can I do?&lt;/P&gt;&lt;P&gt;I have tried to calculate the collumn 3 times...&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 11:06:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175856#M114630</guid>
      <dc:creator>AntonV</dc:creator>
      <dc:date>2023-04-06T11:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175865#M114631</link>
      <description>&lt;P&gt;You can try and create a summary table, like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Summary Table =
ADDCOLUMNS (
    SUMMARIZE ( 'Transactions', 'Transactions'[Company ID], 'Transactions'[Date] ),
    "@cumulative commission",
        VAR CurrentDate = 'Transactions'[Date]
        VAR Result =
            CALCULATE (
                SUM ( 'Transactions'[Commission] ),
                REMOVEFILTERS ( 'Transactions'[Date] ),
                'Transactions'[Date] &amp;lt;= CurrentDate
            )
        RETURN
            Result
)
&lt;/LI-CODE&gt;
&lt;P&gt;This will calculate the cumulative commission for each company for each date which that company has transactions for. If that is successful then we can use that summary table to find the minimum date where the cumulative commission is above the threshold.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 11:16:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175865#M114631</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-04-06T11:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175925#M114634</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;I was able to generate the summary table, but how do I now calculate the date when a company reaches €30?&lt;/P&gt;&lt;P&gt;And how do I calculate the average duration that it takes to get there for all companies?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance. You are a life saver!!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 12:03:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175925#M114634</guid>
      <dc:creator>AntonV</dc:creator>
      <dc:date>2023-04-06T12:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175989#M114640</link>
      <description>&lt;P&gt;Create a one-to-many relationship from the company table to the summary table, then add a new calculated column to the company table,&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Date reached 30 =
CALCULATE (
    MIN ( 'Summary Table'[Date] ),
    'Summary Table'[@cumulative commission] &amp;gt;= 30
)
&lt;/LI-CODE&gt;
&lt;P&gt;You can then create a measure like&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Avg time to 30 =
AVERAGEX (
    FILTER ( Company, NOT ISBLANK ( Company[Date reached 30] ) ),
    DATEDIFF ( Company[Create date], Company[Date reached 30], DAY )
)
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 Apr 2023 12:45:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3175989#M114640</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-04-06T12:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3176033#M114642</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;Thanks a lot for the help. I found what I needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do need to make one more calculation, but I am not sure if it's appropriate to keep asking you questions. If not, you can ingnore my message!&amp;nbsp;&lt;img /&gt;&amp;nbsp;A million thanks either way&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I now need to calculate with the same tables is: "How mutch commission is collected under the €30 bar for each year?"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you have some use cases:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Company 1:&lt;UL&gt;&lt;LI&gt;Y1: €50 commission&lt;/LI&gt;&lt;LI&gt;Only €30 should be included in the calculation&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Company 2:&lt;OL&gt;&lt;LI&gt;Y1: €10 commission&lt;/LI&gt;&lt;LI&gt;Y2: €40 commission&lt;/LI&gt;&lt;LI&gt;Only €30 (€10 + €20) should be included in the calculation&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Company 3:&lt;OL&gt;&lt;LI&gt;Y1: €0&amp;nbsp;commission&lt;/LI&gt;&lt;LI&gt;Y2: €10&amp;nbsp;commission&lt;/LI&gt;&lt;LI&gt;Only €10 should be included in the calculation.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on this I need a total of all commissions earned under €30 per company per year. Hope my explenation is clear...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again really appreciate the help and I hope you have time to help me a little further..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 13:06:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3176033#M114642</guid>
      <dc:creator>AntonV</dc:creator>
      <dc:date>2023-04-06T13:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date range when specific value is reached</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3176080#M114646</link>
      <description>&lt;P&gt;Adapted from&amp;nbsp;&lt;A href="https://www.daxpatterns.com/semi-additive-calculations/," target="_blank"&gt;https://www.daxpatterns.com/semi-additive-calculations/&lt;/A&gt;. Link your date table to the summary table, then create the below measure&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Commission under 30 =
VAR MaxCommissionDates =
    ADDCOLUMNS (
        CROSSJOIN (
            VALUES ( 'Date'[Year] ),
            SUMMARIZE ( 'Summary Table', Company[Company ID] )
        ),
        "@MaxCommissionDate", CALCULATE ( MAX ( 'Summary Table'[Date] ) )
    )
VAR MaxCommissionDatesWithLineage =
    TREATAS ( MaxCommissionDates, 'Date'[Year], Company[ID], 'Date'[Date] )
VAR Result =
    CALCULATE (
        SUMX (
            'Summary Table',
            IF (
                'Summary Table'[Commission] &amp;lt; 30,
                'Summary Table'[Commission],
                'Summary Table'[Commission] - 30
            )
        ),
        MaxCommissionDatesWithLineage
    )
RETURN
    Result
&lt;/LI-CODE&gt;
&lt;P&gt;This should work out the last date for each company in each year, then iterate over those values and subtract 30 if the commission is above 30.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 13:37:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-date-range-when-specific-value-is-reached/m-p/3176080#M114646</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-04-06T13:37:31Z</dc:date>
    </item>
  </channel>
</rss>

