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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

Help to convert subquery to DAX

Hello, I need help converting this SQL into a DAX measure.
The sql looks for purchases that are customer recovery, that is, a customer who made a purchase, his contract expired, and after a while he returned to being a customer.

 

dax_resgate.png

1 ACCEPTED SOLUTION

Attached is one option to do that.  Make sure the filter changes are acceptable.

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

Don't try to "fight the API".  There is no meaningful translator from SQL to DAX. Please explain your business issue and provide sample data and expected outcome.

 

 

I didn't want a translator from SQL to DAX, in the literal sense. I wanted some help to know how to write this SQL in a way that get the same results in Power BI.

This is a dashboard that I'm developing at my job, so I don't think I can share the data.

The company I work for is a site where a teacher can generate tests. He buys credits. Each credit entitles him to enter a question on an exam. When the teacher makes a purchase he has a deadline to use the credits he bought.

I'll try to explain this SQL:
- I look for all purchases of each customer
- For each line (purchase) returned in the SQL, the subquery searches for the last purchase prior to this one and returns the expiration date of that purchase

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Sorry for the late reply and the misunderstanding. Here the link with the sample data: https://drive.google.com/file/d/1XCWUor50r3otSaE5OZYNpHobb3L0gSW2/view?usp=sharing.

The expected result is 171 orders.

Thanks!

Attached is one option to do that.  Make sure the filter changes are acceptable.

It worked out. I had to make some changes, but it helped me a lot. Thank you very much!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors