0% found this document useful (0 votes)
14 views2 pages

Stacked100 With Pivot

This document provides a guide for generating a stacked 100% bar chart in Kusto for student exam results. It includes sample data, transformation steps to calculate percentages for passed and failed exams, and the rendering process. The expected output features student IDs on the X-axis and percentage values on the Y-axis, with a legend indicating passed and failed segments.

Uploaded by

saiakkina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Stacked100 With Pivot

This document provides a guide for generating a stacked 100% bar chart in Kusto for student exam results. It includes sample data, transformation steps to calculate percentages for passed and failed exams, and the rendering process. The expected output features student IDs on the X-axis and percentage values on the Y-axis, with a legend indicating passed and failed segments.

Uploaded by

saiakkina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

To generate a **stacked 100% bar chart** in Kusto (ADX) for students with **passed

and failed exam counts**, follow these steps:

---

### **📌 1. Sample Data**


Assuming your table (`StudentExams`) has columns:
- `StudentId`
- `ExamStatus` → (`"Passed"` or `"Failed"`)
- `ExamCount`

```kql
let StudentExams = datatable(StudentId: string, ExamStatus: string, ExamCount: int)
[
"A", "Passed", 5,
"B", "Failed", 3,
"C", "Passed", 2,
"C", "Failed", 1,
"D", "Passed", 4,
"D", "Failed", 2
];
```

---

### **📌 2. Transform Data for Stacked 100% Bar Chart**


To ensure we always have **both "Passed" and "Failed" columns** for each student,
use `make-series` and calculate **percentages**.

```kql
StudentExams
| summarize ExamCount = sum(ExamCount) by StudentId, ExamStatus
| pivot ExamStatus on ExamStatus with sum(ExamCount)
| extend Passed = coalesce(Passed, 0), Failed = coalesce(Failed, 0) // Ensure both
columns exist
| extend TotalExams = Passed + Failed
| extend PassedPct = todouble(Passed) / TotalExams * 100,
FailedPct = todouble(Failed) / TotalExams * 100
| project StudentId, PassedPct, FailedPct
| render barchart kind=stacked100
```

---

### **📌 Explanation**


1. **Summarize** exam counts **per student per status**.
2. **Pivot** to create separate `"Passed"` and `"Failed"` columns.
3. **Handle missing values** (students with only one status).
4. **Compute total exams** per student.
5. **Calculate percentages** (`PassedPct` and `FailedPct`).
6. **Render as stacked 100% bar chart**.

---

### **📌 Expected Output**


- **X-axis** → `StudentId`
- **Y-axis** → Percentage (100% total per student)
- **Legend** → `"Passed"` and `"Failed"` segments per student.
Would you like to customize this further based on additional criteria? 😊

You might also like