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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
moored
New Member

New Column with If Statement Referencing Previous Value +1

Hi There,

 

I am stuck here and hoping someone can point me in the right direction as I have searched everywhere and am coming up with nothing. I have a table with login tracking data and I need to have a calculated column that is built off the previous value. I can do this very easily in Excel with the following data and formula:

 

  • "LOGIN" value in column B results in +1
  • "SYSLOGOUT" value in column B results in no change
  • Any other value in column B results in -1

 

=IF(B6="LOGIN",E5+1,IF(B6="SYSLOGOUT",E5,E5-1))

 

ABCDE
ATTEMPTDATEATTEMPTRESULTUSERIDLOGINTRACKINGIDCONCURRENT LOGIN COUNT
1/1/2019 1:02SYSLOGOUTDKELLOGG62092590
1/1/2019 3:01SYSLOGOUTMOSTROM62095460
1/1/2019 8:36LOGINGVILLALOBOS62096631
1/1/2019 8:44TIMEOUTGVILLALOBOS62096680
1/1/2019 9:26LOGINANEUZIL62096751

 

moored_0-1604348745261.png

 

Is this even possible in Power BI?

 

Thanks!

-Douglas

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@moored 

you can create two columns

Column = if('Table'[ATTEMPTRESULT]="LOGIN",1,if('Table'[ATTEMPTRESULT]<>"SYSLOGOUT",-1,0))

Column 2 = SUMX(FILTER('Table','Table'[ATTEMPTDATE]<=EARLIER('Table'[ATTEMPTDATE])),'Table'[Column])

1.PNG





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ryan_mayu
Super User
Super User

@moored 

you can create two columns

Column = if('Table'[ATTEMPTRESULT]="LOGIN",1,if('Table'[ATTEMPTRESULT]<>"SYSLOGOUT",-1,0))

Column 2 = SUMX(FILTER('Table','Table'[ATTEMPTDATE]<=EARLIER('Table'[ATTEMPTDATE])),'Table'[Column])

1.PNG





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

Proud to be a Super User!




amitchandak
Super User
Super User

@moored , Try a new column like

Sumx(filter(Table,[USERID] =earlier([USERID]) && [ATTEMPTDATE] <= earlier([ATTEMPTDATE])), if([ATTEMPTRESULT] ="LOGIN", 1, If([ATTEMPTRESULT] = "SYSLOGOUT",0,-1)))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.