>> Download the sample (Power BI)
This sample shows the number and total sales of customers who have bought 2 (or 3) months in a row, from any given month, using the INTERSECT function.
Dashboard - Snippet
Section titled “Dashboard - Snippet”
Data Model - Snippet
Section titled “Data Model - Snippet”
Measures - Sales & Customer
Section titled “Measures - Sales & Customer”No. of Customers buying 2M in a row
Section titled “No. of Customers buying 2M in a row”No. of Customers buying 2M in a row =VAR CustomerTM = VALUES ( Sales_Table[Customer] )VAR CustomerLM = CALCULATETABLE ( VALUES ( Sales_Table[Customer] ), DATEADD ( Calendar_Table[Date], -1, MONTH ) )RETURN COUNTROWS ( INTERSECT ( CustomerTM, CustomerLM ) )No. of Customers buying 3M in a row
Section titled “No. of Customers buying 3M in a row”No. of Customers buying 3M in a row =VAR CustomerTM = VALUES ( Sales_Table[Customer] )VAR CustomerLM = CALCULATETABLE ( VALUES ( Sales_Table[Customer] ), DATEADD ( Calendar_Table[Date], -1, MONTH ) )VAR Customer2M = CALCULATETABLE ( VALUES ( Sales_Table[Customer] ), DATEADD ( Calendar_Table[Date], -2, MONTH ) )RETURN COUNTROWS ( INTERSECT ( INTERSECT ( CustomerTM, CustomerLM ), Customer2M ) )Total Sales
Section titled “Total Sales”Total Sales =SUMX ( Sales_Table, Sales_Table[Unit Price] * Sales_Table[Quantity] )Total Sales (show blanks)
Section titled “Total Sales (show blanks)”Total Sales (show blanks) =IF ( SUMX ( Sales_Table, Sales_Table[Unit Price] * Sales_Table[Quantity] ) = BLANK (), 0, SUMX ( Sales_Table, Sales_Table[Unit Price] * Sales_Table[Quantity] ))Total Sales LM
Section titled “Total Sales LM”Total Sales LM =CALCULATE ( [Total Sales], DATEADD ( Calendar_Table[Date], -1, MONTH ) )Total Sales of Customer buying 2M in a row
Section titled “Total Sales of Customer buying 2M in a row”Total Sales of Customer buying 2M in a row =VAR CustomerTM = VALUES ( Sales_Table[Customer] )VAR CustomerLM = CALCULATETABLE ( VALUES ( Sales_Table[Customer] ), DATEADD ( Calendar_Table[Date], -1, MONTH ) )RETURN CALCULATE ( [Total Sales] + [Total Sales LM], INTERSECT ( CustomerTM, CustomerLM ) )Tables
Section titled “Tables”Calendar_Table
Section titled “Calendar_Table”Calendar_Table =GENERATE ( CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2019, 12, 31 ) ), VAR currentDay = [Date] VAR Day = DAY ( currentDay ) VAR Month = MONTH ( currentDay ) VAR Year = YEAR ( currentDay ) RETURN ROW ( "Day", day, "Month", month, "Year", year ))