Office Script Excel Pivot Table Count Instead of Sum - excel

I'm using Office Script to generate a pivot table and that works. However, for my data hierarchy, I need "count" instead of the default "sum". How do I go about doing that?
I'm adding a hierarchy using the following - this works but summarizes by "sum"
pivotTable.addRowHierarchy(pivotTable.getHierarchy("Company"));
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Unit ID"));
From the script reference page, I need to somehow embed the count function into the above snippet. Does anyone know how to do that? I tried "Record Actions", but it wasn't able to catch the switch from "sum" to "count".
Thanks a lot

Figured it out - to change the summarize function, we need to chain the aggregate function to the end of addDataHierarchy.
The second line in the previous example therefore becomes:
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Unit ID")).setSummarizeBy(ExcelScript.AggregationFunction.count);
For more details refer to setSummarizeBy(summarizeBy).

Related

Power Automate "Vlookup" using Sharepoint Lists - Vlookup resetting

I have the below "Vlookup" , When a record gets submitted in list "Template" I want that to reflect in the list "Aug2021"(Created from an excel sheet) in the "Submitted" column as a "Yes" or "No".
Lookup with between "Project ID" in Template, and "Title" in Aug2021.
IT works fine for the first record submission into "Template", The submitted column shows a "Yes" nicely within list "Aug2021" .
However when I submit a 2nd record, the vlookup resets and that first record will no go to a No. Why is this?
This is what I mean - the flow re runs based on the new record.
When Power Automate does not execute the branch I "think" it "should" execute, that always is because the condition is not met.
The only way to troubleshoot that is to look into what is actually being fed into the Condition. At least while you're still developing.
Initialise two variables at the top, one for the Title and one for the Project ID. Write the Project ID into the variable as soon as you have it. Write the Title into the variable before the Condition step.
Now you can see in the flow run what the values are and you can see the reason for the condition branch being executed.
Also note that the For Each loop will run on all records that are returned bye the Get Items step. This looks like it may write a lot of records that don't match the title.
Edit after comment: You say that the list Aug2021 has 2000 items. Are you attempting to loop through all of them in the flow? That won't work, because the Get Items command only returns a maximum of 100 items.
The flow run screenshot shows that it processed exactly 100 items in the Apply to Each loop. Your screenshot only shows the first one.
Unfortunately, you did not follow my recommendation for troubleshooting, so you still don't know which values are being fed into the condition for each instance of the Apply to Each loop.
If you don't follow advice, I have no idea what else to write.

COUNTIF work arounds for SharePoint lists

I've looked at the following questions already posted in this forum, but neither quite address the specific issue I'm having.
Can I create a COUNTIF calculated column in SharePoint?
How can I build a CountIF function in SharePoint?
I am wondering if SharePoint allows you to reference a certain cells data to then look that value up in a column and count how many of that value there are. These would not be set values, which is why the workarounds proposed in the articles above are not working for me.
EX:In our Excel sheet that we are putting into SharePoint, we are using this formula =COUNTIF($C$2:$C$2007,C2007) and we are trying to translate this into SharePoint.
As shown in the image I've attached, we want a frequency column to calculate how many times each value in the Values column occurs. So the results would end up looking like what's in the image.
Sample Table with Desired Results
Based on my research, SharePoint does not support CountIF function, it is by design.
However, you can use "Group By" as a workaround:
1.Go to the list and click on All Items >> Edit current view
2.On the Edit View page, scroll to "Group By" section and select column that your wanted.

How do I update a list item after adding it with Power Automate

I can't figure out how to do a very simple update of a column value in Power Automate in SharePoint online. I've seen examples of how to update an item on another list, but nothing that updates a value on the same item that was just added and triggered the workflow. Can anybody give me an example and maybe a very brief explanation?
I want to multiply the values of two columns and add it to a third column on the same item which will be blank. I used the formula to update the column I want using values from other columns. =[Dollar Amount]*[% Chance] but it says invalid syntax. There seems to be nothing intuitive in this new power automation and it's a horrible failure compared to how easy it used to be. MS is always making these mistakes.
The first method, you could use a calculated column.
=[% Chance]*[Dollar Amount]
Second method,use Flow.
Test result:
It's Power Automate, not power automation. Details matter.
First, try to set the column value when you create the item. Then you won't have to edit it. If you already know the values for [Dollar amount] and [% Chance] (Chance, really? Or Change?), then you can use these to generate the value before you create the item. You can do that in a variable or with a Compose action. Then create the item and refer to the variable or the Output of the compose action.
If this is not an option, you can use the Edit Item action and get the ID for the item from the action above that you used to create the item.
You say "MS is always making these mistakes." - It's more likely that the problem is a mismatch of data types, e.g. using text fields in calculations, or typos, or wrong syntax. That's not a mistake made by MS. Again, details matter.
Edit after comments: If the workflow is triggered by an item getting created, then you can use an Edit Item action and refer to the ID from the trigger item.

Sharepoint Date and difference

In my list i have created calculated field to get the difference between the last modified date and today's date.
I use the formula
=datedif([modified],[today],"d")
It is throwing an error : The formula contains reference(s) to field(s).
Please advise.
I do not have a separate column to hold today's date.
Regretfully, you cannot use [Today] for calculated fields. Calculated fields only update when an item is modified, so the Today Trick of creating a column named Today, setting your calculated field, then deleting that column, is a bad move.
You have a couple options, the best of which is probably to use JavaScript within a Content Editor Web Part on the page to do the calculation for you. You could also try using SharePoint designer and custom XPath and xslt to get "days since modified" to appear on your page.
Generally, if you want something to identify items that haven't been modified in a while, it should be done with filter library views: they can use [Today], and they don't require tricks or workarounds.

SharePoint: Calculated Column Values Disappear When Editing List Item. Any ideas?

I have a calculated column in a custom SharePoint 2007 list, with the following formula:
=CONCATENATE("IR-",[ID],"-",LEFT(UPPER([Title]),25))
If an item is created in the list, everything is fine, however, when an item is updated the [ID] column is no longer in the calculated column for that item.
So, on creation: "IR-40-TheTitleIsHere", but after edit, it is, "IR--TheTitleIsHere".
Anyone have some insight on why this would be happening?
I confirm the behavior mentioned above. Any Add/Edit will wipe out the [ID] portion. If you edit the column in the list and update the formula, it will update ALL list items to be correct (until you do an edit on the item).
I found this post that mentions the same problem.
Sounds like the only solution would be to make a simple workflow using SharePoint Designer that would update a text field in your list.
I had an issue similar a while back. Through other blogs and experts, I discovered that the [ID] column should not be used in a calculated column because it wreaks havoc and causes many errors. Sorry - remove the ID column and you should be fine.
This question is a little old, but I had the same issue and found a solution for it. It is a pretty specific fix and won't help everyone -- it involves using javascript in a content editor web part to update the calculated field.
This site -- http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/ -- gives an example of how to use javascript in the same manner that I used it.. the important block of code is the first while loop. The point is to grab the out of box ID column from the list and update whatever calculated field needs the ID.
In my case I had a URL in a calculated field that required the ID as a parameter.. of course that wouldn't work normally because you can't put the ID in a calculated field. What I did was I put "?ID=null" in the ID parameter of my calculated field's url, I then replaced that with the ID that was retrieved using javascript.. so whenever the page is loaded, the js kicks off and updates all of the URLs to have the correct ID.
I know this is very old but I couldn't find a newer version of the question anywhere else and the answer above from ferr solved the problem for me but isn't very clear so I thought I'd update it.
This assumes that you want to use the ID in the output HTML (for example within a link), I think this is fairly common.
Using the javascript from the pathtosharepoint link I added in the following to get the id with an if statement for safety:
if (HTMLregexp.test(CellContent)) { //original pathtosharepoint line
if (NodeSet[i].parentNode.getAttribute("iid")){
var SPID = NodeSet[i].parentNode.getAttribute("iid").split(",")[1];
CellContent = CellContent.replace("SPIDReplace", SPID)
}
NodeSet[i].innerHTML = CellContent; //original pathtosharepoint line
This is put in the while loop of the latest pathtosharepoint fix at time of writing. This works for me on SharePoint 2010.
Note: Include the string "SPIDReplace" in your calculated column to get it replaced by the item ID.
pathtosharepoint page: http://blog.pathtosharepoint.com/category/calculated-columns/
pathtosharepoint code: http://pathtosharepoint.com/Downloads

Resources