Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello.
I've summarized our sales table to grab unique customers to its own table. This table is linked to the sales table by customer id. I then added a calculated column to indicate the customers' first completed transaction date for Product A. The DAX looks something like this:
CALCULATE(
SELECTEDVALUE('SALESTABLE'[SALESDATE]),
INDEX(1,
FILTER('SALESTABLE', PRODUCTYPE = "A' && ORDERSTATUS = "COMPLETE"),
ORDERBY( SALESTABLE'[SALESDATE], ASC, SALESTABLE'[ORDER#],ASC),
PARTITIONBY(SALESTABLE'[CUSTOMER_ID]),
MATCHBY(SALESTABLE'[ORDER#]
)
,ALLEXCEPT('SALESTABLE', 'SALESTABLE'[CUSTOMER_ID])
, SALESTABLE'[SALESDATE]
)
So, I have a customer table with unique customers with their respective first purchase date that's linked to the sales table.
This worked for about a year. But, yesterday, the refresh for this report stopped. I get this message:
When I look into the first purchase date Custom Column, this message appears:
I tried looking for duplicated customer id in the summarized customer table and sales order id in the sales table, but I don't find any.
Is there anything wrong with my DAX? Could the duplicate exist somewhere I haven't looked?
Is there a different DAX I can use to find first order date by customer so to circumvent the INDEX error?
Thanks.
Solved! Go to Solution.
Hi @etane,
I hope you are doing well ☺️❤️
So When you use MATCHBY(ORDER#) within each PARTITIONBY(CUSTOMER_ID) Power BI expects that each order number is unique for each customer So the error suggests there might be:
How to Solve This?
First Approach : (If you have SQL access)
SELECT CUSTOMER_ID, ORDER#, COUNT(*)
FROM SALESTABLE
WHERE PRODUCTYPE = 'A' AND ORDERSTATUS = 'COMPLETE'
GROUP BY CUSTOMER_ID, ORDER#
HAVING COUNT(*) > 1
Second Approach : (That's What you need)
This finds the earliest sales date for each customer without complex partitioning logic Using MIN with FILTER:
First Purchase Date Product A =
VAR CurrentCustomer = 'CustomerTable'[CUSTOMER_ID]
RETURN
CALCULATE(
MIN('SALESTABLE'[SALESDATE]),
FILTER(
'SALESTABLE',
'SALESTABLE'[CUSTOMER_ID] = CurrentCustomer &&
'SALESTABLE'[PRODUCTYPE] = "A" &&
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
)
)
First Purchase Date Product A =
CALCULATE(
FIRSTNONBLANK(
'SALESTABLE'[SALESDATE],
1
),
'SALESTABLE'[PRODUCTYPE] = "A",
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
)
First Purchase Date Product A =
MAXX(
TOPN(
1,
CALCULATETABLE(
VALUES('SALESTABLE'[SALESDATE]),
'SALESTABLE'[PRODUCTYPE] = "A",
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
),
'SALESTABLE'[SALESDATE], ASC
),
'SALESTABLE'[SALESDATE]
)
Third Approach:(For handling tie breaking)
First Purchase Date Product A =
VAR FirstTransaction =
TOPN(
1,
FILTER(
'SALESTABLE',
'SALESTABLE'[CUSTOMER_ID] = 'CustomerTable'[CUSTOMER_ID] &&
'SALESTABLE'[PRODUCTYPE] = "A" &&
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
),
'SALESTABLE'[SALESDATE], ASC,
'SALESTABLE'[ORDER#], ASC
)
RETURN
MINX(FirstTransaction, 'SALESTABLE'[SALESDATE])
Bonus Approach:(Debug the duplicates directly)
Create a temporary table to check for duplicates
Duplicate Check =
SUMMARIZE(
FILTER('SALESTABLE', 'SALESTABLE'[PRODUCTYPE] = "A" && 'SALESTABLE'[ORDERSTATUS] = "COMPLETE"),
'SALESTABLE'[CUSTOMER_ID],
'SALESTABLE'[ORDER#],
"Count", COUNTROWS('SALESTABLE')
)
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your threadWant to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Hi,
If you want to have ranking and avoid index you can use RANX. E.g.
Proud to be a Super User!
Thank you for all the responses.
After hours of tinkering, I found a solution (mainly thanks to ChatGPT).
Although I couldn't find any duplicate Order#s, I augmented the MatchBy statement by adding row ID to ensure the DAX isn't held up by a duplicate Order#:
CALCULATE(
SELECTEDVALUE('SALESTABLE'[SALESDATE]),
INDEX(1,
FILTER('SALESTABLE', PRODUCTYPE = "A' && ORDERSTATUS = "COMPLETE"),
ORDERBY( SALESTABLE'[SALESDATE], ASC, SALESTABLE'[ORDER#],ASC),
PARTITIONBY(SALESTABLE'[CUSTOMER_ID]),
MATCHBY(SALESTABLE'[ORDER#], SALESTABLE'[Id]
)
,ALLEXCEPT('SALESTABLE', 'SALESTABLE'[CUSTOMER_ID])
, SALESTABLE'[SALESDATE]
)
Thank you for all the responses.
After hours of tinkering, I found a solution (mainly thanks to ChatGPT).
Although I couldn't find any duplicate Order#s, I augmented the MatchBy statement by adding row ID to ensure the DAX isn't held up by a duplicate Order#:
CALCULATE(
SELECTEDVALUE('SALESTABLE'[SALESDATE]),
INDEX(1,
FILTER('SALESTABLE', PRODUCTYPE = "A' && ORDERSTATUS = "COMPLETE"),
ORDERBY( SALESTABLE'[SALESDATE], ASC, SALESTABLE'[ORDER#],ASC),
PARTITIONBY(SALESTABLE'[CUSTOMER_ID]),
MATCHBY(SALESTABLE'[ORDER#], SALESTABLE'[Id]
)
,ALLEXCEPT('SALESTABLE', 'SALESTABLE'[CUSTOMER_ID])
, SALESTABLE'[SALESDATE]
)
Hi,
If you want to have ranking and avoid index you can use RANX. E.g.
Proud to be a Super User!
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your threadWant to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Sorry for the late reply. Reason I didn't use min function is because I also need to calculate 2nd, 3rd ... Nth transaction dates. That's why the index function works... until the error messages:
Without using INDEX, how can I get the Nth transaction date?
Hi @etane,
is there a reason why you use DAX for this?
Best practise would be to perform this operation somewhere more in the backend.
Maybe give it a try using Power Query with M. Set the query on top of your sales table and create a new one with the same logic.
This deloads also your report during runtime regarding performance.
Second approach but depending on your backend not as easy to implement is to create the table before it gets loaded in Power BI. E.g. in your warehouse or lakehouse.
Best regards!
PS: if you find this helpful, leave some kudos or mark it as solution
It's the only DAX that I know of (actually provided to me by someone in this forum) that provides me with not just the 1st transaction date but also by the Nth transaction date.
I am not good with M.
Hi @etane,
I hope you are doing well ☺️❤️
So When you use MATCHBY(ORDER#) within each PARTITIONBY(CUSTOMER_ID) Power BI expects that each order number is unique for each customer So the error suggests there might be:
How to Solve This?
First Approach : (If you have SQL access)
SELECT CUSTOMER_ID, ORDER#, COUNT(*)
FROM SALESTABLE
WHERE PRODUCTYPE = 'A' AND ORDERSTATUS = 'COMPLETE'
GROUP BY CUSTOMER_ID, ORDER#
HAVING COUNT(*) > 1
Second Approach : (That's What you need)
This finds the earliest sales date for each customer without complex partitioning logic Using MIN with FILTER:
First Purchase Date Product A =
VAR CurrentCustomer = 'CustomerTable'[CUSTOMER_ID]
RETURN
CALCULATE(
MIN('SALESTABLE'[SALESDATE]),
FILTER(
'SALESTABLE',
'SALESTABLE'[CUSTOMER_ID] = CurrentCustomer &&
'SALESTABLE'[PRODUCTYPE] = "A" &&
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
)
)
First Purchase Date Product A =
CALCULATE(
FIRSTNONBLANK(
'SALESTABLE'[SALESDATE],
1
),
'SALESTABLE'[PRODUCTYPE] = "A",
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
)
First Purchase Date Product A =
MAXX(
TOPN(
1,
CALCULATETABLE(
VALUES('SALESTABLE'[SALESDATE]),
'SALESTABLE'[PRODUCTYPE] = "A",
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
),
'SALESTABLE'[SALESDATE], ASC
),
'SALESTABLE'[SALESDATE]
)
Third Approach:(For handling tie breaking)
First Purchase Date Product A =
VAR FirstTransaction =
TOPN(
1,
FILTER(
'SALESTABLE',
'SALESTABLE'[CUSTOMER_ID] = 'CustomerTable'[CUSTOMER_ID] &&
'SALESTABLE'[PRODUCTYPE] = "A" &&
'SALESTABLE'[ORDERSTATUS] = "COMPLETE"
),
'SALESTABLE'[SALESDATE], ASC,
'SALESTABLE'[ORDER#], ASC
)
RETURN
MINX(FirstTransaction, 'SALESTABLE'[SALESDATE])
Bonus Approach:(Debug the duplicates directly)
Create a temporary table to check for duplicates
Duplicate Check =
SUMMARIZE(
FILTER('SALESTABLE', 'SALESTABLE'[PRODUCTYPE] = "A" && 'SALESTABLE'[ORDERSTATUS] = "COMPLETE"),
'SALESTABLE'[CUSTOMER_ID],
'SALESTABLE'[ORDER#],
"Count", COUNTROWS('SALESTABLE')
)
Thank you for your detailed response. I think the MAXX(TopN) function can work. Will try it out first.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 14 | |
| 7 | |
| 4 | |
| 4 | |
| 3 |
| User | Count |
|---|---|
| 23 | |
| 10 | |
| 10 | |
| 6 | |
| 5 |