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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors