Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tmitton
Frequent Visitor

Calculated column based on values in other columns?

I have four surveys feeding into a single Power BI dataset. The four surveys all have different questions, but are related to one another which is why I pulled them into a single data table. Since all of the questions are different, each questions gets its own column and if a column is blank that just means that the corresponding Survey was not completed for that row. 

 

I want to create a calculated column that will identify which survey was completed for that particular row of data. In my example below, if colulmn B contains a value, I want column A to return a value of "Survey #1". If column B does not contain data, I want it to look at columns C, D, and E, and whichever one has a value, tell me which Survey was completed. 

 

I recreated this in excel to try and provide a visual of what I'm trying to do in Power BI. 

 

Power BI Question Screenshot.png

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @tmitton ,

 

Try this calculated column

Calculated column =
"Question#"
    & IF (
        [Qustion#1] = BLANK (),
        IF (
            [Qustion#2] = BLANK (),
            IF ( [Qustion#3] = BLANK (), IF ( [Qustion#4] = BLANK (), BLANK (), 4 ), 3 ),
            2
        ),
        1
    )

19.png

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @tmitton ,

Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.
Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.


Best Regards,
Stephen Tao

v-stephen-msft
Community Support
Community Support

Hi @tmitton ,

 

Try this calculated column

Calculated column =
"Question#"
    & IF (
        [Qustion#1] = BLANK (),
        IF (
            [Qustion#2] = BLANK (),
            IF ( [Qustion#3] = BLANK (), IF ( [Qustion#4] = BLANK (), BLANK (), 4 ), 3 ),
            2
        ),
        1
    )

19.png

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@tmitton Try unpivoting your Question columns in Power Query. (B, C, D, E columns)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.