Solved

Calculated field sharepoint based on 2 fields

Posted on 2014-12-13
5
101 Views
Last Modified: 2014-12-20
Hello,

I need to create a status if an list item is ready for invoicing.


I need a calculated field (field3) with the following characteristics

If field1 has a value then field3 should be 0
if field2 = "Cancelled" then field3 should be 0
If field1 has no value then field3 should be 1

so calculated field3 should be either 0 or 1

thanks!
0
Comment
Question by:Hans de Jongh
  • 2
5 Comments
 

Author Comment

by:Hans de Jongh
Comment Utility
oeps sorry :)
0
 
LVL 50

Accepted Solution

by:
teylyn earned 250 total points
Comment Utility
Oeps, what? Why Powershell? Why Excel?

You can create an IF statement following syntax similar to Excel.

=if(isblank(field1),1,if(or(field2="cancelled,not(isblank(field1))),0,"something else"))

cheers, teylyn
0
 
LVL 18

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 250 total points
Comment Utility
Using powershell to update the field3 value based on the values of field1 and field2:

Replace the listname in the code:

#Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
 
#Variables that we are going to use for list editing
$webURL = <a href="http://portal.contoso.com">http://portal.contoso.com</a>
$listName = "Demo List"
 
#Get the SPWeb object and save it to a variable
$web = Get-SPWeb $webURL
 
#Get the SPList object to retrieve the "Demo List"
$list = $web.Lists[$listName]

#Get all items in this list and save them to a variable
$items = $list.items
 
#Go through all items
foreach($item in $items)
{
if(   ($item["field1"] -ne $null) -or ($item["field2"] -eq "Cancelled" ))
{
$item["field3"] = 0
}
else
{
$item["field3"] = 1
}
 
#Update the item
$item.Update()
}

Open in new window

0
 

Author Closing Comment

by:Hans de Jongh
Comment Utility
thanks both, my question was not clear enough thats why i split the points..
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now