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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
az38
Community Champion
Community Champion

LEFT JOIN with multiple conditions

Hello, DAX-profies!

 

I have a user sessions log

User session could be started at one day and finished at the other

I need to match calendar days and quantity of uniques users who were active a this day

 

So, user_sessions table is:

Session_idUser_idStart_SessionEnd_Session
1124.10.2018 3:0026.10.2018 17:00
2127.10.2018 1:0027.10.2018 3:00
3215.10.2018 3:0020.10.2018 19:00
4304.10.2018 15:0004.10.2018 15:01
5325.10.2018 23:0026.10.2018 2:00

 

It looked like good idea to first create table 

 

Yeardays = CALENDAR(MIN(USER_SESSIONS[Start_Session]);MAX(USER_SESSIONS[End_Session]))

then to left join it with user_sessions using a couple of filters:

 

 

Table = NATURALLEFTOUTERJOIN(Yeardays;filter(USER_SESSIONS;USER_SESSIONS[Start_Session]<NEXTDAY(Yeardays[SessionDay]) && USER_SESSIONS[End_Session]>=Yeardays[SessionDay]))

Precisely, it doesnt work

 

A single value for column 'SessionDay' in table 'Yeardays2' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

I was trying variants but unsuccesfull 😞

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

@az38

 

You can create a calculated table like this:

 

LogInsModified = 
SELECTCOLUMNS(
    GENERATE(
        LogIns,
        VAR St = INT( LogIns[Start_Session] )
        VAR En = INT( LogIns[End_Session] )
        RETURN
        CALENDAR( st, en )
    ),
"Session_id", [Session_id],
"User_ID", [User_id],
"Date", [Date]
)

 

Then relate it to the calendar table and use this simple measure:

 

Active Users = DISTINCTCOUNT( LogInsModified[User_ID] )

Capture.PNG

 


 


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


Proud to be a Datanaut!  

View solution in original post

1 REPLY 1
LivioLanzo
Solution Sage
Solution Sage

@az38

 

You can create a calculated table like this:

 

LogInsModified = 
SELECTCOLUMNS(
    GENERATE(
        LogIns,
        VAR St = INT( LogIns[Start_Session] )
        VAR En = INT( LogIns[End_Session] )
        RETURN
        CALENDAR( st, en )
    ),
"Session_id", [Session_id],
"User_ID", [User_id],
"Date", [Date]
)

 

Then relate it to the calendar table and use this simple measure:

 

Active Users = DISTINCTCOUNT( LogInsModified[User_ID] )

Capture.PNG

 


 


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


Proud to be a Datanaut!  

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.