Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
Expect Output - first_shoppers = 3083
Expect Output - avg_spend_first_d = 134.53
Adding Sample Data:
| report_date | channel | membership_num | demand_revenue |
| 3/1/2023 | OPIC | 6923297 | 473.89 |
| 12/1/2022 | OPIC | 6923297 | 95.57 |
| 3/1/2023 | OPIC | 4732483 | 220.59 |
| 3/1/2023 | OPIC | 7968799 | 54.09 |
| 3/1/2023 | OPIC | 7707891 | 99.94 |
| 3/1/2023 | OPIC | 2953797 | 67.22 |
| 3/1/2023 | OPIC | 2119246 | 173.53 |
| 3/1/2023 | OPIC | 2159933 | 159.96 |
| 3/1/2023 | OPIC | 2276172 | 260.8 |
| 3/1/2023 | OPIC | 5549575 | 99.13 |
| 3/1/2023 | OPIC | 2109264 | 76.79 |
| 3/1/2023 | OPIC | 9386426 | 126.91 |
| 3/1/2023 | OPIC | 6798980 | 82.36 |
| 3/1/2023 | OPIC | 4165529 | 151.66 |
| 3/1/2023 | OPIC | 9276831 | 298.21 |
| 3/1/2023 | OPIC | 4771072 | 106.87 |
| 11/1/2022 | OPIC | 4771072 | 304.89 |
| 3/1/2023 | OPIC | 3956433 | 153.84 |
| 3/1/2023 | OPIC | 1650323 | 100.91 |
| 3/1/2023 | OPIC | 9976085 | 76.52 |
| 3/1/2023 | OPIC | 1061082 | 115.94 |
Full Data
We have to convert this ORACLE SQL(below) query from a legacy system into dax. Each report_date is dynamnic in the legacy system.
This query gets first time shoppers that only placed one order is a specified range, and who have not placed any order 6 month prior starting from start day, hence the MINUS 180 part.
How can I rewrite the query in DAX the includes the MINUS section of -180 that excludes shoppers who placed an order in Power BI?
Here is the query:
Solved! Go to Solution.
@PowerBIET Should be something along these lines. See PBIX attached below signature. Hard to test because you only have a months worth of data.
First Shoppers =
VAR __DaysAgo = 180
VAR __MinRange = MIN('Table'[report_date])
VAR __TableRange1 = SUMMARIZE('Table',[membership_num],"__Count",COUNTROWS('Table'))
VAR __TableRange2 = FILTER(__TableRange1, [__Count] = 1)
VAR __PastRange = FILTER(ALL('Table'),[report_date] < __MinRange && [report_date] >= __MinRange - 180)
VAR __FirstShoppers = DISTINCT(SELECTCOLUMNS(__TableRange2,"__MemberNum",[membership_num]))
VAR __PastShoppers = DISTINCT(SELECTCOLUMNS(__PastRange,"__MemeberNum",[membership_num]))
VAR __MembersOfInterest =
EXCEPT(
__FirstShoppers,
__PastShoppers
)
VAR __Result = COUNTROWS(__MembersOfInterest)
RETURN
__Result
Average Spend =
VAR __DaysAgo = 180
VAR __MinRange = MIN('Table'[report_date])
VAR __TableRange1 = SUMMARIZE('Table',[membership_num],"__Count",COUNTROWS('Table'))
VAR __TableRange2 = FILTER(__TableRange1, [__Count] = 1)
VAR __PastRange = FILTER(ALL('Table'),[report_date] < __MinRange && [report_date] >= __MinRange - 180)
VAR __FirstShoppers = DISTINCT(SELECTCOLUMNS(__TableRange2,"__MemberNum",[membership_num]))
VAR __PastShoppers = DISTINCT(SELECTCOLUMNS(__PastRange,"__MemeberNum",[membership_num]))
VAR __MembersOfInterest =
EXCEPT(
__FirstShoppers,
__PastShoppers
)
VAR __Result = AVERAGEX(FILTER('Table', [membership_num] IN __MembersOfInterest),[demand_revenue])
RETURN
__Result
@PowerBIET Should be something along these lines. See PBIX attached below signature. Hard to test because you only have a months worth of data.
First Shoppers =
VAR __DaysAgo = 180
VAR __MinRange = MIN('Table'[report_date])
VAR __TableRange1 = SUMMARIZE('Table',[membership_num],"__Count",COUNTROWS('Table'))
VAR __TableRange2 = FILTER(__TableRange1, [__Count] = 1)
VAR __PastRange = FILTER(ALL('Table'),[report_date] < __MinRange && [report_date] >= __MinRange - 180)
VAR __FirstShoppers = DISTINCT(SELECTCOLUMNS(__TableRange2,"__MemberNum",[membership_num]))
VAR __PastShoppers = DISTINCT(SELECTCOLUMNS(__PastRange,"__MemeberNum",[membership_num]))
VAR __MembersOfInterest =
EXCEPT(
__FirstShoppers,
__PastShoppers
)
VAR __Result = COUNTROWS(__MembersOfInterest)
RETURN
__Result
Average Spend =
VAR __DaysAgo = 180
VAR __MinRange = MIN('Table'[report_date])
VAR __TableRange1 = SUMMARIZE('Table',[membership_num],"__Count",COUNTROWS('Table'))
VAR __TableRange2 = FILTER(__TableRange1, [__Count] = 1)
VAR __PastRange = FILTER(ALL('Table'),[report_date] < __MinRange && [report_date] >= __MinRange - 180)
VAR __FirstShoppers = DISTINCT(SELECTCOLUMNS(__TableRange2,"__MemberNum",[membership_num]))
VAR __PastShoppers = DISTINCT(SELECTCOLUMNS(__PastRange,"__MemeberNum",[membership_num]))
VAR __MembersOfInterest =
EXCEPT(
__FirstShoppers,
__PastShoppers
)
VAR __Result = AVERAGEX(FILTER('Table', [membership_num] IN __MembersOfInterest),[demand_revenue])
RETURN
__Result
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!
Check out the July 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 29 | |
| 23 | |
| 23 | |
| 22 | |
| 14 |
| User | Count |
|---|---|
| 48 | |
| 33 | |
| 20 | |
| 18 | |
| 16 |