Forum Discussion

LuisLOCapelari's avatar
3 years ago
Solved

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.

 

6 Replies

  • 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.

     

     

    • LuisLOCapelari's avatar
      LuisLOCapelari
      Icon for Helper I rankHelper I

      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