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
MJruud
Frequent Visitor

DAX Correlation Coefficient Measure with pivoted table

Hi, 

I'm working with survey data, and a "best practice" is to pivot the dataset, so we end up with one question column and a corresponding value column for that question. As an example, by doing it this way we can easily do an average of the value column, filter for a specific question, and then get the desired output. However, I am trying to create a correlation measure based on this data structure, and I am not getting the correct output. I am not sure where my error occurs, or if it's even possible to do it this way. Any suggestions are greatly appreciated. 

 

This is my current DAX code: 

Correlation =
VAR _muX =
    CALCULATE (
        AVERAGE ( 'Rawdata pivot'[MetricValue] ),
        FILTER (
            'Rawdata pivot',
            'Rawdata pivot'[Question] = "1: Overall, I am satisfied with my job"
        )
    )
VAR _muY =
    CALCULATE (
        AVERAGE ( 'Rawdata pivot'[MetricValue] ),
        FILTER (
            'Rawdata pivot',
            'Rawdata pivot'[Question] = "2.3: Job requirements: My knowledge and skills are useful in my work"
        )
    )
VAR _numerator =
    SUMX (
        FILTER (
            'Rawdata pivot',
            'Rawdata pivot'[Question] = "1: Overall, I am satisfied with my job"
        ),
        'Rawdata pivot'[MetricValue]
    )
        - _muX
            * SUMX (
                FILTER (
                    'Rawdata pivot',
                    'Rawdata pivot'[Question] = "2.3: Job requirements: My knowledge and skills are useful in my work"
                ),
                'Rawdata pivot'[MetricValue]
            ) - _muY
VAR _denominator =
    SQRT (
        SUMX (
            FILTER (
                'Rawdata pivot',
                'Rawdata pivot'[Question] = "1: Overall, I am satisfied with my job"
            ),
            ( 'Rawdata pivot'[MetricValue] - _muX ) ^ 2
        )
        * SUMX (
            FILTER (
                'Rawdata pivot',
                'Rawdata pivot'[Question] = "2.3: Job requirements: My knowledge and skills are useful in my work"
            ),
            ( 'Rawdata pivot'[MetricValue] - _muY ) ^ 2
        )
    )
RETURN
    DIVIDE ( _numerator, _denominator )
 
Best, 
MR
1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @MJruud ,

 

It's hard for us to find the solution only based on your code and your statement. Please share a sample file with us and show us a screenshot with the result you want. This will make it easier for us to find the solution.

 

Best Regards,
Rico Zhou

 

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

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.