Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions view-samples/kpi-scorecard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# KPI Scorecard

## Summary

This sample formats a list as KPI scorecards. Each tile shows the current value, the change since the previous period, a progress bar with a target marker, and a red/amber/green status stripe.

This is a **Gallery** view format (`kpi-scorecard-gallery.json`): each KPI is a 300 x 200 px tile, and the tiles wrap into as many columns as fit the page.

A **Direction** column tells the format whether higher or lower values are better. This matters for metrics such as customer churn or open defects, where a falling number is an improvement.

![screenshot of the sample](./assets/screenshot.png)

> The screenshot shows the Gallery view in SharePoint with the 20 sample items created by the script.

## How the status is calculated

| Direction | Progress toward target |
|-----------|------------------------|
| Higher | `Value / Target` |
| Lower | `Target / Value` |

Progress of 100% or more always means on target or better.

- **Green**: 100% or more
- **Amber**: 90% to under 100%
- **Red**: under 90%

The trend arrow shows the raw direction of change, but its colour shows whether the change is good for that metric. The 100% and 90% thresholds appear in the colour expressions in the JSON (the `>= 1` and `>= 0.9` tests) and can be changed there. They are repeated in both files, so change them in both.

## View requirements

Use the **Gallery** layout on a list with these columns, using the internal names shown:

| Column | Type | Notes |
|--------|------|-------|
| Title | Single line of text | KPI name |
| Category | Choice | Shown as a chip, for example Finance, Customer, People, Delivery |
| Direction | Choice | `Higher` or `Lower` (which is better) |
| Value | Number | Current value |
| Target | Number | Goal for the period |
| Previous | Number | Value for the previous period |
| Prefix | Single line of text | Optional, for example `$` |
| Suffix | Single line of text | Optional, for example `%`, `h` or `M` |
| Owner | Person | Shown as avatar and name |

### Create the list with a script

[assets/Create List.ps1](./assets/Create%20List.ps1) uses [PnP PowerShell](https://pnp.github.io/powershell/) to create the list and columns, add the sample items below, and create a Gallery view with the format applied:

```powershell
./"Create List.ps1" -SiteUrl "https://contoso.sharepoint.com/sites/team" -ClientId "<app registration client id>"
```

By default the script adds 20 items: six core items plus 14 extra dummy items that cover green, amber and red for both directions, the exact 90% and 100% boundaries, zero values, a blank Direction and a long title. Use `-ScreenshotDataOnly` for just the first six items, `-SkipSampleData` for none, or `-SkipView` to leave out the view. Pass `-OwnerEmails "a@contoso.com","b@contoso.com"` to spread the owners round-robin; otherwise every item is owned by the signed-in user. If the format cannot be applied automatically, the script says so. In that case paste `kpi-scorecard-gallery.json` into **Format current view** > **Advanced mode**.

### Create a view and apply the JSON manually

Use these steps if you already have the list, or if the script could not apply the format. Create the columns from the table above first, using the internal names shown. You need permission to create and edit views on the list.

1. Open the list and select the view drop-down at the top right (for example **All Items**), then **Create new view**.
2. In the **Create view** pane, enter the view name `KPI Scorecard`, choose **Gallery** under **Show as**, and leave **Make this a public view** ticked if others should see it. Select **Create**.

![Create view pane with Gallery selected under Show as](./assets/Gallery.png)

3. Make sure the view shows the columns Title, Category, Direction, Value, Target, Previous, Prefix, Suffix and Owner. Use the view drop-down > **Edit current view** > **Columns** to add any that are missing. A column that is not in the view is not available to the format.
4. Open the layout drop-down at the top right (**List** / **Compact list** / **Gallery**) and check that **Gallery** is selected. Then choose **Format current view**.
5. In the **Format view** pane, make sure **Gallery** is selected, then choose **Advanced mode** at the bottom.
6. Select everything in the editor and delete it. Open [kpi-scorecard-gallery.json](./kpi-scorecard-gallery.json), copy the whole file and paste it in. The first line of the pasted JSON should reference `tile-formatting.schema.json`.
7. Select **Preview** to check the tiles, then **Save**.

### Using the Gallery view

- Pick the view from the view drop-down at the top right. Other views on the list are not affected.
- Select a tile to open the item. Tiles are a fixed size and wrap to fit the page width.
- To change the thresholds, colours or tile size, open **Format current view** > **Advanced mode** again and edit the JSON. The tile size is the `height` and `width` at the top of `kpi-scorecard-gallery.json`.
- To remove the formatting, open **Format current view** > **Advanced mode**, clear the editor and save.

> This is a tile format, so it only works in the Gallery layout. In a List view, the Preview shows an error or the format is ignored. If the view looks unformatted, check that the layout shown in the **Format view** pane is **Gallery**.

### Sample data

The first six items used for the screenshot:

| Title | Category | Direction | Value | Target | Previous | Prefix | Suffix |
|-------|----------|-----------|-------|--------|----------|--------|--------|
| Revenue | Finance | Higher | 4.2 | 4 | 3.8 | $ | M |
| Net Promoter Score | Customer | Higher | 41 | 50 | 38 | | |
| Customer churn | Customer | Lower | 3.1 | 2.5 | 3.4 | | % |
| Avg resolution time | Delivery | Lower | 6.2 | 8 | 7.1 | | h |
| Employee engagement | People | Higher | 78 | 80 | 79 | | % |
| Open defects | Delivery | Lower | 42 | 20 | 35 | | |

## Notes and limitations

- Tiles are a fixed 300 x 200 px; long titles and owner names are truncated with an ellipsis.
- Totals across KPIs are not possible in view formatting.
- If **Target** is 0 or less, progress is shown as 100%. If **Value** and **Target** are both 0, the bar is empty.
- If **Direction** is blank, the tile is treated as higher-is-better.

## Sample

Solution|Author(s)
--------|---------
kpi-scorecard-gallery.json | [sudeepghatak](https://github.com/sudeepghatak)

## Version history

Version|Date|Comments
-------|----|--------
1.0|December 1, 2026|Initial release
1.1|December 1, 2026|Changed to a Gallery view format

## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**

---

<img src="https://m365-visitor-stats.azurewebsites.net/list-formatting/view-samples/kpi-scorecard" />
135 changes: 135 additions & 0 deletions view-samples/kpi-scorecard/assets/Create List.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<#
.SYNOPSIS
Creates a "KPIs" list with the columns and sample items used by the KPI Scorecard sample,
then creates a Gallery view and applies the tile format (kpi-scorecard-gallery.json).

.DESCRIPTION
Requires PnP.PowerShell (https://pnp.github.io/powershell/) and an Entra ID app registration
that you pass as -ClientId. Run it as a user who can create lists on the target site.

.EXAMPLE
./"Create List.ps1" -SiteUrl "https://contoso.sharepoint.com/sites/team" -ClientId "00000000-0000-0000-0000-000000000000"

.EXAMPLE
# Spread the dummy items across several owners
./"Create List.ps1" -SiteUrl "..." -ClientId "..." -OwnerEmails "ana@contoso.com","raj@contoso.com"

.EXAMPLE
# Columns only, no sample items and no view formatting
./"Create List.ps1" -SiteUrl "..." -ClientId "..." -SkipSampleData -SkipView
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)] [string] $SiteUrl,
[Parameter(Mandatory)] [string] $ClientId,
[string] $ListName = "KPIs",
[string] $ViewName = "KPI Scorecard",
# Path to the Gallery (tile) format JSON. Defaults to kpi-scorecard-gallery.json, one folder up from this script.
[string] $FormatPath = (Join-Path (Split-Path $PSScriptRoot -Parent) "kpi-scorecard-gallery.json"),
# Optional list of people (emails or UPNs) to assign as Owner, round-robin. Defaults to the signed-in user.
[string[]] $OwnerEmails,
[switch] $SkipSampleData,
# Only add the six items shown in the README screenshot, not the extra dummy data.
[switch] $ScreenshotDataOnly,
[switch] $SkipView
)

$ErrorActionPreference = "Stop"

# Connect to SharePoint
Connect-PnPOnline -Url $SiteUrl -ClientId $ClientId -Interactive

# Create the list (stop if it already exists so existing data is never overwritten)
if (Get-PnPList -Identity $ListName -ErrorAction SilentlyContinue) {
throw "A list named '$ListName' already exists on this site. Choose another -ListName or delete the list first."
}
New-PnPList -Title $ListName -Template GenericList -OnQuickLaunch | Out-Null
Set-PnPList -Identity $ListName -Description "KPIs with value, target, previous period and direction, shown as gallery tiles." | Out-Null

# Add columns. Internal names must match the ones used in kpi-scorecard-gallery.json.
Add-PnPField -List $ListName -DisplayName "Category" -InternalName "Category" -Type Choice -AddToDefaultView `
-Choices @("Finance", "Customer", "People", "Delivery", "Operations") | Out-Null
Add-PnPField -List $ListName -DisplayName "Direction" -InternalName "Direction" -Type Choice -AddToDefaultView `
-Choices @("Higher", "Lower") | Out-Null
Add-PnPField -List $ListName -DisplayName "Value" -InternalName "Value" -Type Number -AddToDefaultView | Out-Null
Add-PnPField -List $ListName -DisplayName "Target" -InternalName "Target" -Type Number -AddToDefaultView | Out-Null
Add-PnPField -List $ListName -DisplayName "Previous" -InternalName "Previous" -Type Number -AddToDefaultView | Out-Null
Add-PnPField -List $ListName -DisplayName "Prefix" -InternalName "Prefix" -Type Text -AddToDefaultView | Out-Null
Add-PnPField -List $ListName -DisplayName "Suffix" -InternalName "Suffix" -Type Text -AddToDefaultView | Out-Null
Add-PnPField -List $ListName -DisplayName "Owner" -InternalName "Owner" -Type User -AddToDefaultView | Out-Null

Write-Host "List '$ListName' created with all columns." -ForegroundColor Green

# Seed sample items
if (-not $SkipSampleData) {
# Owner is a Person column. Use the supplied people, or the signed-in user for every item.
if (-not $OwnerEmails) {
$OwnerEmails = @((Get-PnPWeb -Includes CurrentUser).CurrentUser.Email)
}

# The six items shown in the README screenshot.
$items = @(
@{ Title = "Revenue"; Category = "Finance"; Direction = "Higher"; Value = 4.2; Target = 4; Previous = 3.8; Prefix = '$'; Suffix = "M" },
@{ Title = "Net Promoter Score"; Category = "Customer"; Direction = "Higher"; Value = 41; Target = 50; Previous = 38; Prefix = ""; Suffix = "" },
@{ Title = "Customer churn"; Category = "Customer"; Direction = "Lower"; Value = 3.1; Target = 2.5; Previous = 3.4; Prefix = ""; Suffix = "%" },
@{ Title = "Avg resolution time"; Category = "Delivery"; Direction = "Lower"; Value = 6.2; Target = 8; Previous = 7.1; Prefix = ""; Suffix = "h" },
@{ Title = "Employee engagement"; Category = "People"; Direction = "Higher"; Value = 78; Target = 80; Previous = 79; Prefix = ""; Suffix = "%" },
@{ Title = "Open defects"; Category = "Delivery"; Direction = "Lower"; Value = 42; Target = 20; Previous = 35; Prefix = ""; Suffix = "" }
)

# Extra dummy data. Together with the items above this covers green, amber and red for both
# directions, the exact 90% and 100% boundaries, zero values, a blank Direction and a long title.
if (-not $ScreenshotDataOnly) {
$items += @(
# Higher is better
@{ Title = "Gross margin"; Category = "Finance"; Direction = "Higher"; Value = 42; Target = 40; Previous = 41; Prefix = ""; Suffix = "%" }, # green, improving
@{ Title = "Pipeline value"; Category = "Finance"; Direction = "Higher"; Value = 3.2; Target = 3; Previous = 2.7; Prefix = '$'; Suffix = "M" }, # green, improving
@{ Title = "On-time delivery"; Category = "Delivery"; Direction = "Higher"; Value = 96; Target = 95; Previous = 97; Prefix = ""; Suffix = "%" }, # green, but slipping
@{ Title = "Customer satisfaction"; Category = "Customer"; Direction = "Higher"; Value = 4.3; Target = 4.5; Previous = 4.4; Prefix = ""; Suffix = " / 5" }, # amber, slipping
@{ Title = "New customers"; Category = "Customer"; Direction = "Higher"; Value = 118; Target = 150; Previous = 124; Prefix = ""; Suffix = "" }, # red, slipping
@{ Title = "Training completion"; Category = "People"; Direction = "Higher"; Value = 90; Target = 100; Previous = 82; Prefix = ""; Suffix = "%" }, # amber, exactly 90%
# Lower is better
@{ Title = "Cost per ticket"; Category = "Finance"; Direction = "Lower"; Value = 12.4; Target = 11; Previous = 13.1; Prefix = '$'; Suffix = "" }, # red, but improving
@{ Title = "Employee attrition"; Category = "People"; Direction = "Lower"; Value = 11.5; Target = 10; Previous = 10.2; Prefix = ""; Suffix = "%" }, # red, worsening
@{ Title = "Support backlog"; Category = "Operations"; Direction = "Lower"; Value = 85; Target = 100; Previous = 110; Prefix = ""; Suffix = "" }, # green, improving
@{ Title = "Security incidents"; Category = "Operations"; Direction = "Lower"; Value = 2; Target = 2; Previous = 5; Prefix = ""; Suffix = "" }, # green, exactly 100%
@{ Title = "Page load time"; Category = "Operations"; Direction = "Lower"; Value = 2.1; Target = 2; Previous = 2.4; Prefix = ""; Suffix = " s" }, # amber, improving
# Edge cases
@{ Title = "Critical outages"; Category = "Operations"; Direction = "Lower"; Value = 0; Target = 0; Previous = 1; Prefix = ""; Suffix = "" }, # zero value: treated as 100%
@{ Title = "Customer onboarding time to first value"; Category = "Delivery"; Direction = "Lower"; Value = 14; Target = 10; Previous = 16; Prefix = ""; Suffix = " days" }, # long title
@{ Title = "Brand awareness"; Category = "Customer"; Value = 33; Target = 40; Previous = 30; Prefix = ""; Suffix = "%" } # blank Direction: treated as higher-is-better
)
}

$i = 0
foreach ($item in $items) {
$item.Owner = $OwnerEmails[$i % $OwnerEmails.Count]
Add-PnPListItem -List $ListName -Values $item | Out-Null
$i++
}
Write-Host "Added $($items.Count) sample items (owners: $($OwnerEmails -join ', '))." -ForegroundColor Green
}

# Create the Gallery view and apply the tile format
if (-not $SkipView) {
if (-not (Test-Path $FormatPath)) {
Write-Warning "Format file not found at '$FormatPath'. Skipping the view; paste the JSON in manually."
return
}
$json = Get-Content -Path $FormatPath -Raw

$fields = @("Title", "Category", "Direction", "Value", "Target", "Previous", "Prefix", "Suffix", "Owner")
$view = Add-PnPView -List $ListName -Title $ViewName -Fields $fields -SetAsDefault

try {
# ViewType2 = TILES switches the view to the Gallery layout; the tile format is stored in CustomFormatter.
Set-PnPView -List $ListName -Identity $view -Values @{ ViewType2 = "TILES"; CustomFormatter = $json } | Out-Null
Write-Host "Gallery view '$ViewName' created with the tile format applied." -ForegroundColor Green
}
catch {
Write-Warning "Could not apply the format automatically: $($_.Exception.Message)"
Write-Host "Finish manually: open the view, switch it to Gallery, then Format current view > Advanced mode and paste $(Split-Path $FormatPath -Leaf)." -ForegroundColor Yellow
}
}

Write-Host "Done. Open: $SiteUrl/Lists/$ListName" -ForegroundColor Cyan
Binary file added view-samples/kpi-scorecard/assets/Gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions view-samples/kpi-scorecard/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"name": "pnp-list-formatting-kpi-scorecard",
"reponame": "kpi-scorecard",
"version": "1.0.0.0",
"source": "pnp",
"title": "KPI Scorecard",
"shortDescription": "This sample displays each KPI as a gallery tile with the current value, target progress, trend against the previous period and red/amber/green status.",
"url": "https://github.com/pnp/list-formatting/tree/master/view-samples/kpi-scorecard",
"longDescription": [
"This sample formats a Gallery view so that each KPI is a tile. Each tile shows the KPI name, category, owner, current value with optional prefix and suffix, the change since the previous period, and a progress bar with a target marker. A Direction column controls whether higher or lower values are better, so metrics such as churn or defect counts are coloured correctly."
],
"creationDateTime": "2026-12-01T00:00:00.000Z",
"updateDateTime": "2026-12-01T00:00:00.000Z",
"products": [
"SharePoint",
"Microsoft Lists"
],
"categories": [
"Status / Progress"
],
"metadata": [
{
"key": "LIST-SAMPLE-TYPE",
"value": "View"
},
{
"key": "SHAREPOINT-COMPATIBILITY",
"value": "SharePoint Online"
},
{
"key": "SAMPLE-CATEGORIES",
"value": "Cards, Status / Progress, Trending"
},
{
"key": "LIST-COLUMN-TYPE",
"value": ""
},
{
"key": "FORMATTING-TOKENS",
"value": ""
},
{
"key": "FORMATTING-OPERATORS",
"value": "abs, floor, getUserImage"
},
{
"key": "FORMATTING-ACTIONS",
"value": ""
},
{
"key": "FORMATTING-FEATURES",
"value": "hideSelection"
},
{
"key": "CLASSES",
"value": ""
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/List-Formatting/master/view-samples/kpi-scorecard/assets/screenshot.png",
"alt": "KPI tiles in a Gallery view showing values, trends, target progress bars and red, amber and green status edges"
}
],
"authors": [
{
"gitHubAccount": "sudeepghatak",
"pictureUrl": "https://github.com/sudeepghatak.png"
}
],
"references": [
{
"name": "Use view formatting to customize SharePoint",
"description": "You can use view formatting to customize how items in SharePoint lists and libraries are displayed. To do this, you construct a JSON object that describes the elements that are displayed when an item is loaded in a view and any styles to be applied to those elements.",
"url": "https://docs.microsoft.com/sharepoint/dev/declarative-customization/view-formatting"
}
]
}
]
Binary file added view-samples/kpi-scorecard/assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading