Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 43 | |
| 39 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 67 | |
| 63 | |
| 30 | |
| 30 | |
| 23 |