cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jackj
Helper I
Helper I

Determine if a user ID appears in a prior week

I have the following table, and I'm looking to create a column that looks at the UserID, and returns the UserID if that ID appeared in the previous week.  My data table is similar to the below:

 

UserID     Visit Week

123456    1/1/2021

123457    1/1/2021

123458    1/1/2021

123459    1/1/2021

123460    1/1/2021

123461    1/1/2021

123462    1/1/2021

123456    1/8/2021

123457    1/8/2021

123459    1/8/2021

123461    1/8/2021

123457    1/15/2021

123460    1/15/2021

123461    1/15/2021

123462    1/15/2021

 

All I'm looking to do is add a column that returns the UserID only if that appeared in the previous week, otherwise, leave blank.  Is this possible?  Would anyone be able to help with the DAX for this?

Thanks in advance!

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Community Champion
Community Champion

Hi, @jackj 

I assume you want to see the ID list that only shows the last week, not the whole past weeks.

Please check the below picture and the sample pbix file's link down below.

 

Picture3.png

 

Previous Week Visit ID CC =
VAR previousweekdate = 'Table'[Visit Week] - 7
VAR previousweekvisitlist =
SUMMARIZE (
FILTER ( 'Table', 'Table'[Visit Week] = previousweekdate ),
'Table'[UserID]
)
RETURN
IF ( 'Table'[UserID] IN previousweekvisitlist, 'Table'[UserID] )
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

View solution in original post

2 REPLIES 2
Jihwan_Kim
Community Champion
Community Champion

Hi, @jackj 

I assume you want to see the ID list that only shows the last week, not the whole past weeks.

Please check the below picture and the sample pbix file's link down below.

 

Picture3.png

 

Previous Week Visit ID CC =
VAR previousweekdate = 'Table'[Visit Week] - 7
VAR previousweekvisitlist =
SUMMARIZE (
FILTER ( 'Table', 'Table'[Visit Week] = previousweekdate ),
'Table'[UserID]
)
RETURN
IF ( 'Table'[UserID] IN previousweekvisitlist, 'Table'[UserID] )
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

View solution in original post

AlB
Super User III
Super User III

Hi @jackj 

New Col = 
VAR currentWeek_ = Table1[Visit Week]
VAR previousWeek_ =
    CALCULATE (
        MAX ( Table1[Visit Week] ),
        Table1[Visit Week] < currentWeek_,
        ALL ( Table1 )
    )
VAR usersPreviousWeek_ =
    CALCULATETABLE (
        DISTINCT ( Table1[UserID] ),
        Table1[Visit Week] = previousWeek_,
        ALL ( Table1 )
    )
RETURN
    IF ( Table1[UserID] IN usersPreviousWeek_, Table1[UserID] )

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors