Forum Discussion

EFont's avatar
EFont
New Member
3 years ago
Solved

Logical clause for a join ?

Hello !

 

I would like to get a list of active years per users, based on the years between their start and end dates.

My Issue is that I do not have the possibility to add Stored Procedures on my provider's database.

So, I am trying in DAX instead

 

First, here's an idea of how I would have done it in SQL :

 

 

Select u.USerID, y.Year
From vwUsers u left join vwYears y
on y.Year between (u.UserDateHired and coalesce(u.UserDateTerminated, Date.Now()))

 

 

 

Through DAX, I created the following :

 

 

ctUserActivity =
Var curDay = Today()
Return SELECTCOLUMNS(vwUsers, "UserID", [UserID],  "DateStarted", [UserDateAdded], "DateEnded", COALESCE([UserDateInactivated], curDay))

 

 

 

So I have my user info ready to join with my Calendar table... But I don't see how to state a logical clause for the join

 

Here is a data sample of what I would like to obtain:

UserIDActivity
1010102010
1010102011
1010102012
1010102013
1010102014
1010102015
1010102016
2020202019
2020202020
2020202021
2020202022
2020202023
3030302021
3030302022
3030302023

 

Please help !

 

Thank you,

Erik

  • Roughly speaking, use GENERATEALL(vwUsers, FILTER(vwYears, ...)) to realize LEFT JOIN effect.

5 Replies

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

    Roughly speaking, use GENERATEALL(vwUsers, FILTER(vwYears, ...)) to realize LEFT JOIN effect.

    • EFont's avatar
      EFont
      New Member

      Indeed !!!

       

      I played a bit with GenerateAll

      Once I understood its power, I managed to do it from my sample's elements

      The next step was to apply it to my solution and it works !

       

      I also made a groupby on my calendar table to get only the years to simplify the results into a ctYears table, here is the resulting code

      ctUserActivityAndYear = GENERATEALL(ctUserActivity,filter(ctYears,and(ctYears[Year] >= ctUserActivity[DateStarted].[Year], ctYears[Year] <= ctUserActivity[DateEnded].[Year])))

       

      Here is the resulting table

       

      CNENFRNL, I thank you very much ! 

      Have an excellent weekend !

  • Just saw that the result table is not showing properly, here is an image instead: