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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MatejZukovic
Resolver I
Resolver I

Flag if value existed week ago or not

Hi,

 

I have data set with 2 columns - Week and User. Data indicates weeks when users have been part of certain group. I would like to create new column (New User) that will compare Week with previous week. If the user is not found in a previous week, I'd like to return "Yes". If user can be found in table in previous week, I'd like to return "No". 

 

Example: For Week 2 I'd like to see "Yes" for John as there is no data showing John was part of the group in Week 1. For Week 3, I'd like to see "No" because John was part of a group in Week 2.

 

Hope it's clear enough 🙂

 

Any help is appreciated.

Thanks!

Matej

 

MatejZukovic_1-1598620566801.png

 

 

 

3 ACCEPTED SOLUTIONS
fhill
Resident Rockstar
Resident Rockstar

New User = IF( ISBLANK( CALCULATE( SUM('Table'[Week]), FILTER(ALL('Table'), 'Table'[User] = EARLIER('Table'[User])
&& 'Table'[Week] = (EARLIER('Table'[Week]) -1) )) ) , "YES", "NO")

 

Let me know if this works?  *** Calculations like this are DEPENDENT on your data being Properly SORTED First! **

P.S.  Do we need to take into account First / Last week of the year?   (if Week 1 -1 woudl be 0, look for 52 instead?)

 

fhill_0-1598622300897.png

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

amitchandak
Super User
Super User

@MatejZukovic , measure approch is this week vs last week, you can week rank of week but need to separate table

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

Column way =

new user =if(isblank(countx(filter(table,[user]=earlier([user]) && [week] =earlier([week]) -1),[user])),"Yes","No")

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

Sorry, ignore the 'Sory' comment, I was thinking of a differnt situation...

 

Obvioustly there's multiple way to solve this based on all the posts.  Here's one way to take YEARS and Weeks into consideration.

New User = IF ( TableByUser[Week] <> 1,
IF( ISBLANK( CALCULATE( SUM('TableByUser'[Week]), FILTER(ALL('TableByUser'), 'TableByUser'[User] = EARLIER('TableByUser'[User]) && TableByUser[Year] = EARLIER(TableByUser[Year])
&& 'TableByUser'[Week] = (EARLIER('TableByUser'[Week]) -1) )) ) , "YES", "NO")
, IF( ISBLANK( CALCULATE( SUM('TableByUser'[Week]), FILTER(ALL('TableByUser'), 'TableByUser'[User] = EARLIER('TableByUser'[User]) && TableByUser[Year] = (EARLIER(TableByUser[Year]) - 1)
&& 'TableByUser'[Week] = 52 )) ) , "YES", "NO")

 

fhill_0-1598625858273.png

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@MatejZukovic , measure approch is this week vs last week, you can week rank of week but need to separate table

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

Column way =

new user =if(isblank(countx(filter(table,[user]=earlier([user]) && [week] =earlier([week]) -1),[user])),"Yes","No")

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
lkalawski
Resident Rockstar
Resident Rockstar

@MatejZukovic ,

 

Try this measure:

New User =
VAR _prweek =
    SELECTEDVALUE ( Users[Week] ) - 1
VAR _user =
    SELECTEDVALUE ( Users[User] )
VAR _Cnt =
    CALCULATE (
        COUNTROWS ( Users ),
        FILTER ( ALL ( Users ), Users[Week] = _prweek && Users[User] = _user )
    )
RETURN
    SWITCH ( TRUE (), _Cnt > 0, "No", "Yes" )



_______________
If I helped, please accept the solution and give kudos! 😀

fhill
Resident Rockstar
Resident Rockstar

New User = IF( ISBLANK( CALCULATE( SUM('Table'[Week]), FILTER(ALL('Table'), 'Table'[User] = EARLIER('Table'[User])
&& 'Table'[Week] = (EARLIER('Table'[Week]) -1) )) ) , "YES", "NO")

 

Let me know if this works?  *** Calculations like this are DEPENDENT on your data being Properly SORTED First! **

P.S.  Do we need to take into account First / Last week of the year?   (if Week 1 -1 woudl be 0, look for 52 instead?)

 

fhill_0-1598622300897.png

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Hi @fhill , your solution works perfectly. Great point on first / last week of the year. How would you approach it? Also, can you elaborate bit more on data must be sorted properly?

 

Thanks a ton,

Matej

Sorry, ignore the 'Sory' comment, I was thinking of a differnt situation...

 

Obvioustly there's multiple way to solve this based on all the posts.  Here's one way to take YEARS and Weeks into consideration.

New User = IF ( TableByUser[Week] <> 1,
IF( ISBLANK( CALCULATE( SUM('TableByUser'[Week]), FILTER(ALL('TableByUser'), 'TableByUser'[User] = EARLIER('TableByUser'[User]) && TableByUser[Year] = EARLIER(TableByUser[Year])
&& 'TableByUser'[Week] = (EARLIER('TableByUser'[Week]) -1) )) ) , "YES", "NO")
, IF( ISBLANK( CALCULATE( SUM('TableByUser'[Week]), FILTER(ALL('TableByUser'), 'TableByUser'[User] = EARLIER('TableByUser'[User]) && TableByUser[Year] = (EARLIER(TableByUser[Year]) - 1)
&& 'TableByUser'[Week] = 52 )) ) , "YES", "NO")

 

fhill_0-1598625858273.png

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.