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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
kc_1116
New Member

Two dropdown menus to select two columns and calculate the difference/correlation

Hi,

 

I am looking to create two dropdown menus to select two arbitary persons from the data set and calculate the difference in each day or the correlation.

 

kc_1116_0-1741486166898.png

 

The original dataset in in wide format. Mindful that it is not the ideal format in Power BI, I have unpivot it into a long format.

DayAnneBillCharlesDavidEvan
1122.533
2232.521
3342.512

 

However, I struggled to create a calculate the score difference between two person in each day. I tried to use do so by using NATURALJOIN and SELECTEDVALUE, but SELECTEDVALUE always return empty instead of what is selected in the dropdown menu.

 

Please find below the link to my Power BI file

https://limewire.com/d/997fa681-3d66-4657-a310-6a6901ef5466#iQGXUyBikm-_s5Ox-hS2APKQ5G5LUEo7NrGi5-r2...

 

Can you point me to the right direction please? Thanks a million.

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @kc_1116 

For pairwise comparison calculations, I would suggest setting up the model in a similar way to the "Comparing different time periods" pattern.

 

I have attached your PBIX modified to use this method.

 

This is how I would suggest setting up the model:

OwenAuger_0-1741509786450.png

  • This avoids duplicating the Data table.
  • Measure values based on filters on 'Person 2' rely on DAX to remove filters on 'Person 1' and activate the relationship between 'Person 1' and 'Person 2' (see below).

You can then write measures like these:

 

Score Person 1 = 
SUM ( Data[Score] )
Score Person 2 = 
CALCULATE (
    [Score Person 1],
    REMOVEFILTERS ( 'Person 1' ),
    USERELATIONSHIP ( 'Person 1'[Person 1], 'Person 2'[Person 2] )
)
Variance Person 1 vs Person 2 = 
[Score Person 1] - [Score Person 2]
Coefficient of Determination = 
VAR RegressionResult =
    LINESTX (
        VALUES ( Days[Day] ),
        [Score Person 2],
        [Score Person 1]
    )
VAR Result =
    SELECTCOLUMNS ( RegressionResult, [CoefficientOfDetermination] )
RETURN
    Result

 

Note: For the measures using LINESTX, (Coefficient of Determination, Slope and Intercept), I treated Score Person 2 as the dependent variable and Score Person 1 as the independent variable. You may well want to switch these around.

 

OwenAuger_1-1741509991050.png

Would something like this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

(Virus scan in progress ...)
2 REPLIES 2
OwenAuger
Super User
Super User

Hi @kc_1116 

For pairwise comparison calculations, I would suggest setting up the model in a similar way to the "Comparing different time periods" pattern.

 

I have attached your PBIX modified to use this method.

 

This is how I would suggest setting up the model:

OwenAuger_0-1741509786450.png

  • This avoids duplicating the Data table.
  • Measure values based on filters on 'Person 2' rely on DAX to remove filters on 'Person 1' and activate the relationship between 'Person 1' and 'Person 2' (see below).

You can then write measures like these:

 

Score Person 1 = 
SUM ( Data[Score] )
Score Person 2 = 
CALCULATE (
    [Score Person 1],
    REMOVEFILTERS ( 'Person 1' ),
    USERELATIONSHIP ( 'Person 1'[Person 1], 'Person 2'[Person 2] )
)
Variance Person 1 vs Person 2 = 
[Score Person 1] - [Score Person 2]
Coefficient of Determination = 
VAR RegressionResult =
    LINESTX (
        VALUES ( Days[Day] ),
        [Score Person 2],
        [Score Person 1]
    )
VAR Result =
    SELECTCOLUMNS ( RegressionResult, [CoefficientOfDetermination] )
RETURN
    Result

 

Note: For the measures using LINESTX, (Coefficient of Determination, Slope and Intercept), I treated Score Person 2 as the dependent variable and Score Person 1 as the independent variable. You may well want to switch these around.

 

OwenAuger_1-1741509991050.png

Would something like this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
(Virus scan in progress ...)

Thanks so much for solving the problem and explaining everthing in details. You made my day 😀

Helpful resources

Announcements