Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi, I am looking for help if it is possible to add a column value based on the values from two other columns.
I have two possible values for the Class Name column based on the Course Name and whether a student is in 7 or 8 Grade.
The Class Name values need to be either "7 Mathematics" or "8 Mathematics". The first image below is what I am hoping for it to look like.
If this addition below can be added it would be fantastic!
If the Course Name value is any of these with the green checks that name would just be duplicated in the Class Name column.
So basically copy the Course Name values to the Class Name column unless they are math classes and then assign either of the two corrected values.
Solved! Go to Solution.
1. Identify a primary key in your data. In your case that is a composite key made up of Course Name and Student Grade which I implemented as a calculated column
2. Right click on that primary key column and create (or edit) a group. Now you can bucket collections of primary keys into your Class groups.
3. Use the Class groups column in your visuals.
The same can be achieved with lots of code in either Power Query or DAX, but the column group method is more convenient, and it is sufficient if you don't expect your data to change frequently.
@lbendlin Thank you very much for your continued help. Below is some sample data with the results field being the Class Name column. Most of the values are the same as the Course Name column. All students need to be in either 7 Mathematics or 8 Mathematics based on their grade level and regardless of what actual math class they are in.
Course Name | Student Grade | Class Name |
7 English | 7 | 7 English |
7 Integrated Science | 7 | 7 Integrated Science |
7 Language Arts | 7 | 7 Language Arts |
7 Mathematics | 7 | 7 Mathematics |
7/8 Algebra I | 7 | 7 Mathematics |
7/8 Algebra I | 8 | 8 Mathematics |
8 English | 8 | 8 English |
8 Integrated Science | 8 | 8 Integrated Science |
8 Language Arts | 8 | 8 Language Arts |
8 Mathematics | 8 | 8 Mathematics |
Algebra II/Trig | 8 | 8 Mathematics |
Hon. Algebra II/Trig | 8 | 8 Mathematics |
@lbendlin That looks fantastic! I appreciate you. Could you give me a quick explanation of how the "Class Name" column gets the values?
1. Identify a primary key in your data. In your case that is a composite key made up of Course Name and Student Grade which I implemented as a calculated column
2. Right click on that primary key column and create (or edit) a group. Now you can bucket collections of primary keys into your Class groups.
3. Use the Class groups column in your visuals.
The same can be achieved with lots of code in either Power Query or DAX, but the column group method is more convenient, and it is sufficient if you don't expect your data to change frequently.
@lbendlin I did some reading on that and appreciate you steering me to a totally new area that I have not used in PBI before. I still cannot figure out how to apply that to my desired outcome.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523
Read about Column Groups. Much easier to create and maintain.
User | Count |
---|---|
118 | |
66 | |
65 | |
56 | |
50 |
User | Count |
---|---|
181 | |
85 | |
67 | |
61 | |
53 |