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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
jennibelle22
New Member

New column based off values in two different related tables

I've got a data set of survey results and I'm struggling a bit with a particular new column creation that will help me conduct correlation analysis between the answers to different questions in the survey. I've tried out a few of the solutions I found in this forum, but they haven't worked thus far (details below). I'm pretty sure I'm missing something basic in how my data model is set up or the filter functions I'm using.

 

Data Model:

Not every question is the same format (some Likert scales, some Y/N, some frequency scales, that sort of thing), hence the slightly greater complexity to the data model. I can change the model, but haven't figured out a more useful set of relationships to change it to.

 

'SurveyResults' 'Questions' 'QuestionTypes'

[RespondentID]

[Question]

[Response]

[NewColumn]

Linked by

Many to One

[Question]

[Question]

[QuestionCategory]

[QuestionType]

[PositivityIndex]

Linked by

Many to Many

[QuestionType]

[QuestionType]

[ResponseOptions]

[ResponseValue]

 

'Questions'[PositivityIndex] is a +/- 1 value based on the phrasing of the question. Eg. some questions if you 'strongly agree' that's a good thing relating to a +1, and some that's a bad thing so the index would be -1.

'QuestionTypes'[ResponseValue] is a decimal based on the response. Eg. for a Likert style question the response 'strongly agree' would have a larger value than 'agree'.

 

What I'm trying to create is a new column in the 'SurveyResults' table that assigns a numerical value to each response based on the combination of the relevant PositivityIndex and ResponseValue so that I have a numerical for each individual response, rather than just the text 'Strongly Agree'.

 

I tried the following:

NewColumn = related( 'QuestionTypes'[ResponseValue]) * related('Questions'[PositivityIndex])

It errored and said the column either doesn't exist or doesn't have a relationship to any table available in the current context. Then I realised duh, that doesn't give a link at all to 'SurveyResults'[Response] so of course it didn't come up with anything.

 

After a bit of searching around I tried filtering more explicitly and just getting a clear link to the ResponseValue to start with rather than the full calculation:

NewColumn = calculate( related('QuestionTypes'[ResponseValue]), 'QuestionTypes'[QuestionType] = 'Questions'[QuestionType], 'QuestionTypes'[ResponseOptions] = 'SurveyResults'[Response])

Got the same error, so I fiddled around with related functions and got nowhere.

 

I'm pretty comfortable when I'm dealing with just two tables and reasonably simple calculations, but the relationships in this one have stretched my basic DAX skills, alas. Help?

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

HI @jennibelle22 

 

Try this:

NewColumn =
VAR QuestionType = RELATED('Questions'[QuestionType])
VAR PositivityIndex = RELATED('Questions'[PositivityIndex])
VAR ResponseValue = LOOKUPVALUE(
    'QuestionTypes'[ResponseValue],
    'QuestionTypes'[QuestionType], QuestionType,
    'QuestionTypes'[ResponseOptions], 'SurveyResults'[Response]
)
RETURN
    IF(
        NOT(ISBLANK(ResponseValue)),
        ResponseValue * PositivityIndex,
        0  // or another default value
    )

 

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

Appreciate your Kudos!! 

 

LinkedIn|Twitter|Blog |YouTube 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

HI @jennibelle22 

 

Try this:

NewColumn =
VAR QuestionType = RELATED('Questions'[QuestionType])
VAR PositivityIndex = RELATED('Questions'[PositivityIndex])
VAR ResponseValue = LOOKUPVALUE(
    'QuestionTypes'[ResponseValue],
    'QuestionTypes'[QuestionType], QuestionType,
    'QuestionTypes'[ResponseOptions], 'SurveyResults'[Response]
)
RETURN
    IF(
        NOT(ISBLANK(ResponseValue)),
        ResponseValue * PositivityIndex,
        0  // or another default value
    )

 

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

Appreciate your Kudos!! 

 

LinkedIn|Twitter|Blog |YouTube 

Thank-you!!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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