Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calculated field sharepoint based on 2 fields

Posted on 2014-12-13
5
104 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
ID: 40498109
oeps sorry :)
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst earned 250 total points
ID: 40498435
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 19

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 250 total points
ID: 40498807
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
ID: 40510870
thanks both, my question was not clear enough thats why i split the points..
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

856 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