Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have seen many posts related to customer retention but none that fit my situation. I'm new to Power BI / DAX so changing the examples for my situation has been difficult.
What I'm trying to do:
Dataset:
Steps:
------------------------------------------------------------ -- Identify new customers for a given period ------------------------------------------------------------ ------------------------------------------------------------ -- Get Customer First Purchase Date ------------------------------------------------------------ DROP TABLE #Customer_First_Purchase_Date select a.CustomerKey , min(a.ShipDate) as 'First_Purchase_Date' into #Customer_First_Purchase_Date from [dbo].[FactInternetSales] a group by a.CustomerKey ------------------------------------------------------------ -- Identify new customers that purchased from product category 4 ------------------------------------------------------------ drop table #NewCustomers_Selected_Items_Dates select distinct a.CustomerKey , eomonth(First_Purchase_Date,0) as First_Purchase_Date into #NewCustomers_Selected_Items_Dates from #Customer_First_Purchase_Date a inner join [dbo].[FactInternetSales] b on a.CustomerKey = b.CustomerKey and a.First_Purchase_Date = b.ShipDate inner join continuousimprovement.dbo.DimProductData c on c.ProductKey = b.ProductKey where c.ProductCategoryKey = 4 order by 1 ------------------------------------------------------------ -- Get Totals - Paste to Excel and create pivot table ------------------------------------------------------------ select a.CustomerKey , a.First_Purchase_Date , eomonth(b.ShipDate,0) as 'ShipDate_Month' , count(distinct a.CustomerKey) as 'NumCust' from #NewCustomers_Selected_Items_Dates a inner join [dbo].[FactInternetSales] b on a.CustomerKey = b.CustomerKey inner join continuousimprovement.dbo.DimProductData c on c.ProductKey = b.ProductKey group by a.CustomerKey , a.First_Purchase_Date , eomonth(b.ShipDate,0) order by 1
Thanks for your help!
Solved! Go to Solution.
Hi @rob2,
Try this formula, please.
Measure = VAR purchasedFristDay = CALCULATETABLE ( VALUES ( FactInternetSales[CustomerKey] ), FILTER ( ALL ( FactInternetSales[FirstPurchaseDate], FactInternetSales[ShipDate], FactInternetSales[FirstPurchaseDate_Month] ), [FirstPurchaseDate] = FactInternetSales[ShipDate] && FactInternetSales[FirstPurchaseDate_Month] = MIN ( FactInternetSales[FirstPurchaseDate_Month] ) ), ALL ( 'Calendar' ) ) RETURN CALCULATE ( DISTINCTCOUNT ( FactInternetSales[CustomerKey] ), FILTER ( ALL ( FactInternetSales ), FactInternetSales[CustomerKey] IN purchasedFristDay && FactInternetSales[FirstPurchaseDate] < FactInternetSales[ShipDate] && YEAR ( FactInternetSales[ShipDate] ) = YEAR ( MIN ( 'Calendar'[Date_USFormat] ) ) && MONTH ( FactInternetSales[ShipDate] ) = MONTH ( MIN ( 'Calendar'[Date_USFormat] ) ) ) )
Best Regards,
Dale
Hi @rob2,
Try this formula, please.
Measure = VAR purchasedFristDay = CALCULATETABLE ( VALUES ( FactInternetSales[CustomerKey] ), FILTER ( ALL ( FactInternetSales[FirstPurchaseDate], FactInternetSales[ShipDate], FactInternetSales[FirstPurchaseDate_Month] ), [FirstPurchaseDate] = FactInternetSales[ShipDate] && FactInternetSales[FirstPurchaseDate_Month] = MIN ( FactInternetSales[FirstPurchaseDate_Month] ) ), ALL ( 'Calendar' ) ) RETURN CALCULATE ( DISTINCTCOUNT ( FactInternetSales[CustomerKey] ), FILTER ( ALL ( FactInternetSales ), FactInternetSales[CustomerKey] IN purchasedFristDay && FactInternetSales[FirstPurchaseDate] < FactInternetSales[ShipDate] && YEAR ( FactInternetSales[ShipDate] ) = YEAR ( MIN ( 'Calendar'[Date_USFormat] ) ) && MONTH ( FactInternetSales[ShipDate] ) = MONTH ( MIN ( 'Calendar'[Date_USFormat] ) ) ) )
Best Regards,
Dale
Very nice Dale! I will review and better undertand your approach in order to improve my skills. Tx!
Hi,
I am not sure of how much i can help but i'd like to try. Please share data in an MS Excel file format.
@Ashish_Mathur Thanks for looking. Here is the Excel file.
https://www.dropbox.com/s/2p74h00ewkdvxkz/AdventureWorksExcel%20File.xlsx?dl=0
Hi @rob2,
Try out this solution, please.
1. Add a column in the table [FactInternetSales].
FirstPurchaseDate = CALCULATE ( MIN ( FactInternetSales[ShipDate] ), ALLEXCEPT ( FactInternetSales, FactInternetSales[CustomerKey] ) )
2. Create a measure.
Measure = VAR purchasedFristDay = CALCULATETABLE ( VALUES ( FactInternetSales[CustomerKey] ), FILTER ( FactInternetSales, [FirstPurchaseDate] = FactInternetSales[ShipDate] ) ) RETURN CALCULATE ( DISTINCTCOUNT ( FactInternetSales[CustomerKey] ), FILTER ( ALL ( FactInternetSales ), FactInternetSales[CustomerKey] IN purchasedFristDay && FactInternetSales[FirstPurchaseDate] < FactInternetSales[ShipDate] ) )
Please don't share sensitive data here.
Best Regards,
Dale
@v-jiascu-msft I added the measures (new PBIX file below) and not giving me the expected results.
New file with measure: https://www.dropbox.com/s/oqv5r5k9gxo8oor/AdventureWorks.pbix?dl=0
I'm getting the results below (#'s should tie out the #'s in my original post).
User | Count |
---|---|
117 | |
74 | |
62 | |
50 | |
46 |
User | Count |
---|---|
174 | |
125 | |
60 | |
60 | |
57 |