Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
ubv
Frequent Visitor

Equivalent of SQL subquery

Hi,

 

I have a simple table Sales with the daily sales per client:

day           client.         spentUSD

20200501.    a.               5000

20200501.    b.                490

20200502.    b                3000

....

 

I need to build a dashboard where the user can select two days and they can see the clients gained/lost: 

- two tables: one with the clients gained (in the example above empty) and another table with the clients lost (client #a)

- two cards: showing the number of clients gained (0) and lost (1)

 

Conceptually it's very straight-forward, but I cannot make it work. In SQL I'd use something like :

select * from Sales where day = $selectedDay1 and client not in (select client from Sales where day = $selectedDay2)

 

Any ideas? I tried using "NOT IN" but couldn't make it work with dynamic values (the ones in the slicers).

 

Thanks,

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @ubv ,

 

Check this link: https://www.daxpatterns.com/new-and-returning-customers/

 

Did I answer your question? Mark my post as a solution!
Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @ubv ,

 

Why you need two selected days to calculate client gained and lost? Would you please tell me what is the logic for it?

 

In my mind, we just need one selected day:

 

Gained client: clients who appeared on the selected date and have not appeared before

Lost client: clients who have not appeared on the selected date and appeared before.

 

Is my idea correct, please correct me?

 

Best Regards,

Dedmon Dai

camargos88
Community Champion
Community Champion

Hi @ubv ,

 

Check this link: https://www.daxpatterns.com/new-and-returning-customers/

 

Did I answer your question? Mark my post as a solution!
Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors