<?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: Recurring Customers in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3578194#M137987</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="658644" data-lia-user-login="joseluis1969240" class="lia-mention lia-mention-user"&gt;joseluis1969240&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I built this measure using the Contoso data model and it gave me the expected results, please modify as per your model and try:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales Returning Customers =
VAR YearMax =
    MAX ( 'Date'[Fiscal Year] )
VAR Actual_Customer =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax
    )
VAR Actual_Customer_1Yr =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax - 1
    )
VAR Actual_Customer_2Yr =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax - 2
    )
VAR ActualvsYr1 =
    INTERSECT ( Actual_Customer, Actual_Customer_1Yr )
VAR ActualvsYr2 =
    INTERSECT ( Actual_Customer, Actual_Customer_2Yr )
VAR RecurringCustomers =
    DISTINCT ( UNION ( ActualvsYr1, ActualvsYr2 ) )
RETURN
    CALCULATE ( [Sales Amount], RecurringCustomers )&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 11 Dec 2023 19:17:43 GMT</pubDate>
    <dc:creator>Fowmy</dc:creator>
    <dc:date>2023-12-11T19:17:43Z</dc:date>
    <item>
      <title>Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3576129#M137873</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;I'm trying to define a measure in DAX that provides me with the amount of recurring sales per customer for each fiscal year I choose. In my case, recurring sales for, let's say, fiscal year 2024 (01/04/2023-30/04/2024) refer to the amount of sales to customers in fiscal year 2024 when I've sold to these customers in fiscal year 2023 or fiscal year 2022. In other words, if the customer has sales in either or both of the previous two fiscal years, the customer is considered recurrent.&lt;/P&gt;&lt;P&gt;To achieve this, I've developed the following measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Sales Returning Customers:=Var YearMax=MAX(Calendario[Fiscal_Year_1])&lt;BR /&gt;Var Actual_Customer=CALCULATETABLE(VALUES(Ventas[Customer Account]);Calendario[Fiscal_Year_1]=YearMax)&lt;BR /&gt;Var Past_Customers=CALCULATETABLE(VALUES(Ventas[Customer Account]);&lt;STRONG&gt;DATESBETWEEN(Calendario[Date];DATE(2021;04;01);DATE(2023;03;31))&lt;/STRONG&gt;)&lt;BR /&gt;Var Cross=INTERSECT(Past_Customers;Actual_Customer)&lt;BR /&gt;Return&lt;BR /&gt;CALCULATE([Sales];Cross)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above measure works well, BUT I would like to make the function "&lt;STRONG&gt;DATESBETWEEN(Calendar[Date], DATE(2021, 04, 01), DATE(2023, 03, 31))&lt;/STRONG&gt;" dynamic (work in a filtered context). Is this possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking forward to your response. Thank you very much in advance.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 10 Dec 2023 11:18:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3576129#M137873</guid>
      <dc:creator>joseluis1969240</dc:creator>
      <dc:date>2023-12-10T11:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3576153#M137875</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="658644" data-lia-user-login="joseluis1969240" class="lia-mention lia-mention-user"&gt;joseluis1969240&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please check if the following would work for you?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales Returning Customers:=
Var YearMax = MAX(Calendario[Fiscal_Year_1])
Var Actual_Customer=
	CALCULATETABLE(
		VALUES(Ventas[Customer Account]);
		Calendario[Fiscal_Year_1] = YearMax
	)
Var Past_Customers=
	CALCULATETABLE(
		VALUES(Ventas[Customer Account]);
		Calendario[Fiscal_Year_1] = YearMax-1
		
	)
Var Cross=INTERSECT(Past_Customers;Actual_Customer)
Return
	CALCULATE(
		[Sales];
		Cross
	)&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 10 Dec 2023 12:28:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3576153#M137875</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2023-12-10T12:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3578161#M137982</link>
      <description>&lt;P&gt;Good evening, The approach you propose doesn’t work for me because it doesn’t take into account that, in my case, recurring sales are those that occur in the two years prior to the current one. Let me give you some examples: -Customers with sales in the previous year (01/04/2022-31/03/2023), THESE SALES ARE RECURRING&lt;BR /&gt;-Customers with sales in the year 01/04/2021-31/03/2022, THESE SALES ARE RECURRING&lt;BR /&gt;-Customers with sales in the year 01/04/2022-31/03/2023 and in the year 01/04/2021-31/03/2022, THESE SALES ARE RECURRING&lt;BR /&gt;-Customers with sales in the year 01/04/2023-31/03/2024 and no sales in the two previous years, THESE SALES ARE NEW (ACTUAL CUSTOMER)&lt;/P&gt;&lt;P&gt;Considering the previous examples, the approach I’m using involves the DATESBETWEEN function. Can you think of any other solution?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2023 18:25:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3578161#M137982</guid>
      <dc:creator>joseluis1969240</dc:creator>
      <dc:date>2023-12-11T18:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3578194#M137987</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="658644" data-lia-user-login="joseluis1969240" class="lia-mention lia-mention-user"&gt;joseluis1969240&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I built this measure using the Contoso data model and it gave me the expected results, please modify as per your model and try:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales Returning Customers =
VAR YearMax =
    MAX ( 'Date'[Fiscal Year] )
VAR Actual_Customer =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax
    )
VAR Actual_Customer_1Yr =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax - 1
    )
VAR Actual_Customer_2Yr =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax - 2
    )
VAR ActualvsYr1 =
    INTERSECT ( Actual_Customer, Actual_Customer_1Yr )
VAR ActualvsYr2 =
    INTERSECT ( Actual_Customer, Actual_Customer_2Yr )
VAR RecurringCustomers =
    DISTINCT ( UNION ( ActualvsYr1, ActualvsYr2 ) )
RETURN
    CALCULATE ( [Sales Amount], RecurringCustomers )&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 11 Dec 2023 19:17:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3578194#M137987</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2023-12-11T19:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3579767#M138058</link>
      <description>&lt;P&gt;Good afternoon:&lt;BR /&gt;Thank you very much, the measure works very well. I have tried to use this measure by modifying it to create two new measures: NEW CUSTOMERS AND LOST CUSTOMERS. I am not able to obtain the desired results, could you please continue helping me?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;NEW CUSTOMERS: CUSTOMERS WITH SALES IN THE CURRENT FISCAL YEAR AND NO SALES IN THE PREVIOUS TWO FISCAL YEARS&lt;/LI&gt;&lt;LI&gt;LOST CUSTOMERS: CUSTOMERS WITH NO SALES IN THE LAST THREE FISCAL YEARS&lt;BR /&gt;If it's not too much to ask, would you be so kind to detail the code for both measures? Do I need to open a new post to ask you these new questions?&lt;BR /&gt;Thank you in advance for your help.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 12 Dec 2023 13:10:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3579767#M138058</guid>
      <dc:creator>joseluis1969240</dc:creator>
      <dc:date>2023-12-12T13:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3580568#M138101</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="658644" data-lia-user-login="joseluis1969240" class="lia-mention lia-mention-user"&gt;joseluis1969240&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Measure for new customers:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;New Customers =
VAR YearMax =
    MAX ( 'Date'[Fiscal Year] )
VAR Actual_Customer =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax
    )
VAR Actual_Customer_1Yr =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax - 1
    )
VAR Actual_Customer_2Yr =
    CALCULATETABLE (
        VALUES ( 'Sales'[CustomerKey] ),
        'Date'[Fiscal Year] = YearMax - 2
    )
VAR Year1_2 =
    DISTINCT ( UNION ( Actual_Customer_1Yr, Actual_Customer_2Yr ) )
VAR Result =
    EXCEPT ( Actual_Customer, Year1_2 )
RETURN
    CALCULATE ( [Sales Amount], Result )
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;Measure for lost customers:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Lost Customers =
VAR YearMax =
    MAX ( 'Date'[Fiscal Year] )
VAR Result =
    SUMX (
        VALUES ( Customer[CustomerKey] ),
        VAR __Sales3yrs =
            CALCULATE (
                [Sales Amount],
                'Date'[Fiscal Year]
                    IN {
                        YearMax,
                        YearMax - 1,
                        YearMax - 2
                    }
            )
        VAR __Salesbefore3yrs =
            CALCULATE ( [Sales Amount], 'Date'[Fiscal Year] &amp;lt; YearMax - 2 )
        RETURN
            IF ( ISBLANK ( __Sales3yrs ), __Salesbefore3yrs )
    )
RETURN
    Result
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 20:17:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3580568#M138101</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2023-12-12T20:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582027#M138179</link>
      <description>&lt;P&gt;Good afternoon:&lt;/P&gt;&lt;P&gt;Thank you again for your help. The measure that calculates sales to new customers works perfectly; however, I'm having trouble implementing the measure that calculates sales from lost customers. Power Pivot is giving me the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;As you can see, I've copied the measure you provided (adjusting the field names accordingly). Could you assist me again?&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 13:53:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582027#M138179</guid>
      <dc:creator>joseluis1969240</dc:creator>
      <dc:date>2023-12-13T13:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582083#M138183</link>
      <description>&lt;P&gt;You missed a bracket:&lt;BR /&gt;IF ( ISBLANK ( __Sales3yrs&lt;STRONG&gt; )&lt;/STRONG&gt;, __Salesbefore3yrs )&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 14:17:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582083#M138183</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2023-12-13T14:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582318#M138197</link>
      <description>&lt;P&gt;Good afternoon again:&lt;/P&gt;&lt;P&gt;I've just corrected the error you pointed out, but I'm still facing an issue: &lt;STRONG&gt;the measure doesn't support filters&lt;/STRONG&gt;, meaning if I create a pivot table with the 'customer' field and the "lost customers" measure, and try to filter a specific year (for example: 2024), the pivot table doesn't display any data... Could this measure be modified to show results when filters are applied? Lastly, &lt;STRONG&gt;I would like to ask if it's possible to dynamically determine the number of lost customers&lt;/STRONG&gt; as well as the amount of their sales.&lt;/P&gt;&lt;P&gt;Thank you again for your patience. Best regards,&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 15:59:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582318#M138197</guid>
      <dc:creator>joseluis1969240</dc:creator>
      <dc:date>2023-12-13T15:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582679#M138222</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="658644" data-lia-user-login="joseluis1969240" class="lia-mention lia-mention-user"&gt;joseluis1969240&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please try this measure for lost customers, it shows the count. I am not sure if the amount makes sense here.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Lost Customers = 
Var YearMax = MAX('Date'[Fiscal Year])
var Result = 
    SUMX(
        VALUES( Customer[CustomerKey] ),
        VAR __Sales3yrs = 
            CALCULATE(
               COUNTROWS( VALUES(Sales[CustomerKey] ) ),
                'Date'[Fiscal Year] IN { YearMax , YearMax-1  ,  YearMax-2    }        
            )
        VAR __Salesbefore3yrs = 
           CALCULATE(
               COUNTROWS( VALUES(Sales[CustomerKey] ) ),
                'Date'[Fiscal Year] &amp;lt;  (YearMax-2)
            )
        
        RETURN 
            IF( __Sales3yrs &amp;lt;&amp;gt; 1 &amp;amp;&amp;amp; __Salesbefore3yrs =1 ,  1 )
    )
RETURN
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Dec 2023 20:35:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3582679#M138222</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2023-12-13T20:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Recurring Customers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3583426#M138250</link>
      <description>&lt;P&gt;Good morning:&lt;BR /&gt;The measure you mentioned works perfectly, &lt;STRONG&gt;but I need it to work dynamically&lt;/STRONG&gt;. Let me explain: if I generate a pivot table with the 'customer name' field and the 'lost customers' measure, the pivot table's result is correct. &lt;STRONG&gt;HOWEVER, if I apply a filter to the pivot table by 'fiscal year,' the table appears without data&lt;/STRONG&gt;. Could you please help me modify the measures you've taught me &lt;STRONG&gt;to make them work when I apply filters by year in pivot tables?&lt;/STRONG&gt; These are the last two measures you provided and that I need to function when I apply filters to the pivot tables in which I use them:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much again&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 08:03:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recurring-Customers/m-p/3583426#M138250</guid>
      <dc:creator>joseluis1969240</dc:creator>
      <dc:date>2023-12-14T08:03:22Z</dc:date>
    </item>
  </channel>
</rss>

