- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CASE Statement to DAX
So I have the below:
CASE
WHEN [Academic Career] = Undergraduate THEN [CGPA UG]
WHEN [Academic Career] = Masters THEN [CGPA GR]
ELSE 'No CGPA'
END
How do I change this into DAX for Power BI? Is such an approach possible in DAX? [Academic Career], [CGPA UG], and [CGPA GR] are columns. I want to create a new column that grabs the value from each of those two columns based on the case statement.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was in a hurry and didn't close my parentheses.
MeasureorColumn= SWITCH( Table[Academic Career], "Undergraduate",FORMAT(Table[CGPA UG], "General Number"), "Masters", FORMAT(Table[CGPA GR], "General Number"), "No CGPA" )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So if I understand you correctly, you have 2 columns for different levels of CGPA undergrad and grad, and you want to merge them into one column that shows what was in CGPA UG if they're an undergrad and CGPA GR if they're a grad student. Is that correct?
CGPAMerged = SWITCH( TableName[Academic Career], "Undergraduate", TableName[CGPA UG], "Master's", TableName[CGPA GR], BLANK() )
This would give you a single column that would merge the 2 based on the student's level in column AB in your sample data. The last argument returns blank if their career is anything other than undergraduate or master's. Then a simple measure like
Avg CGPA = AVERAGE(TableName[CGPAMerged])
...would give you the average per plan if you placed it on a chart along with column AC.
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know of any reason for that. The new CGPAMerged column you created is on the same table as Academic Plan, just like in the sample data, right? And the measure is an average of that new column?
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi. Use SWITCH Function
MeasureorColumn=Switch(Table[Academic Career],"Undergraduate",Table[CGPA UG];"Masters",Table[CGPA GR],Table[NO CGPA])
Lima - Peru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nested IF statements will do the trick:
=IF (
[Academic Career] = "Undergraduate",
[CGPA UG],
IF ( [Academic Career] = "Masters", [CGPA GR], "No CGPA" )
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @JoeSQL,
I tried that and got the message "Expressions that yield variant data-type cannot be used to define calculated columns."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm guessing [CGPA UG] and/or [CGPA GR] contain numbers. You're getting that error because No CGPA is a text data type. Try substituting "No CGPA" with 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What data type is the [CGPA GR] column?
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is Decimal Numbers. In some cases the values present as "null" instead of just showing "0". Zero means they do not have a CGPA at that level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the FORMAT function to change the numbers to strings. Something like...
MeasureorColumn= SWITCH( Table[Academic Career], "Undergraduate",FORMAT(Table[CGPA UG], "General Number", "Masters", FORMAT(Table[CGPA GR], "General Number", "No CGPA" )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was in a hurry and didn't close my parentheses.
MeasureorColumn= SWITCH( Table[Academic Career], "Undergraduate",FORMAT(Table[CGPA UG], "General Number"), "Masters", FORMAT(Table[CGPA GR], "General Number"), "No CGPA" )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@KHorseman 10,000 thank you's!!! That did it!!!
Now that I have the values in one column labeled as [**bleep** GPA]. Do I have to create another calculated column that takes the values and turns them into integers and treats the "No CGPA" as 0? Is there an approach for this? DAX is a brave new world to me but the more I come across the more I learn.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure I understand what you're asking. What is the purpose of this other column?
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @KHorseman,
The column we created was a result of our student information system outputting CGPA for students in different columns instead of giving one CGPA column. So CGPA UG would have a CGPA populate if the students academic career level was undergraduate and their CGPA GR column would show as 0. Same thing if they are a graduate student, the CGPA UG column would show as 0 and the CGPA GR column would show a number. I wanted to be able to reflect as an average by degree program so I figured I needed to get CGPA regardless of UG or GR in one column and allow the column for academic program to be the point for which CGPA was pivoted. Each row represents a student.
I created a demo excel file based on the real data so that I don't violate FERPA Law: https://drive.google.com/open?id=0BxvqEMoNpMLiYUl4bjlmRE5scVk
So CGPA UG is presented in column U and CGPA GR is presented in column V. Note that some students have a 0 in CGPA UG and GR. That would be the case if they don't have a CGPA yet because they withdrew from their courses denoted by a W in column Y.
The individuals Academic Career is presented in column AB.
So I figured if I could get CGPA in one column and use column AC I could then say the Average CGPA for students in the MS in Aeronautics is X.XX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So if I understand you correctly, you have 2 columns for different levels of CGPA undergrad and grad, and you want to merge them into one column that shows what was in CGPA UG if they're an undergrad and CGPA GR if they're a grad student. Is that correct?
CGPAMerged = SWITCH( TableName[Academic Career], "Undergraduate", TableName[CGPA UG], "Master's", TableName[CGPA GR], BLANK() )
This would give you a single column that would merge the 2 based on the student's level in column AB in your sample data. The last argument returns blank if their career is anything other than undergraduate or master's. Then a simple measure like
Avg CGPA = AVERAGE(TableName[CGPAMerged])
...would give you the average per plan if you placed it on a chart along with column AC.
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @KHorseman. That worked perfectly. I would never have got the SWITCH thing. totally a new language for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just wait until you need to use a SWITCH in a measure instead of a column. It's easy once you understand what's going on but often confusing the first time you try.
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@KHorseman I don't know whether to be optimistic or afraid!
The below is the dashboard that all of this work helped create. I am assuming the measure created to get the average CGPA is the reason why when selecting an Academic Plan from the filters at the top is what keeps the CGPA from changing with the rest of the information?
the CGPA visual is created using Card.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
According to the structure you showed in your sample data that card should change when you select something in that Academic Plan slicer. Check visual interactions and make sure you don't have interactions turned off between that card and that slicer.
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I checked and the interaction is turned on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And no matter what you select in that slicer, it still says the average is 3.30?
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
02-01-2023 11:59 AM | |||
Anonymous
| 10-15-2020 12:14 PM | ||
04-19-2023 12:53 PM | |||
08-22-2018 10:49 AM | |||
05-22-2024 06:51 AM |
User | Count |
---|---|
126 | |
113 | |
71 | |
65 | |
46 |