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
Popeye55
New Member

Trying to create a dax query to compare one persons test scores to the average of the others

I would like to be able to use a slicer to select someone by their ID number and then display a line chart where one line is the selected individual's scores over time and the other is the average of everone esle. Is this possible using DAX queries?

Here is an example of the data:

ID numberQ1 scoreQ2 scoreQ3 scoreQ4 score
175546786
280365475
390769084

For example if i selected ID# 1 the first line in the chart would show his scores and the second line would average the other two people's scores.

1 ACCEPTED SOLUTION
BITomS
Resolver III
Resolver III

Hi @Popeye55 ,

 

I think the first thing you need to do is unpivot your data table as I don't see a date field to create your 'view over time'. Details on how to do this are here: https://support.microsoft.com/en-us/office/unpivot-columns-power-query-0f7bad4b-9ea1-49c1-9d95-f5882...

 

So your table would effectively look like this:

 

IDScoreDate
17501/01/2022 (or whatever Q1 start date is)
15401/04/2022 (or whatever Q2 start date is)
16701/07/2022 (or whatever Q3 start date is)
18601/10/2022 (or whatever Q4 start date is)
28001/01/2022 (or whatever Q1 start date is)
23601/04/2022 (or whatever Q2 start date is)
25401/07/2022 (or whatever Q3 start date is)
27501/10/2022 (or whatever Q4 start date is)
etc.etc.etc.

 

Then you could have one measure just as = AVERAGE('TABLE'[Score]) . This will update to show a single ID in your line chart when the ID has been selected from a slicer.

 

Your second measure for the overall average would be = CALCULATE(AVERAGE('TABLE'[Score]),ALL('TABLE'[ID])) . This will ignore any slicer selection made by a user.

 

If you want to exclude the user selected ID, the second measure above can be enhanced by using = CALCULATE(AVERAGE('TABLE'[Score]),ALL('TABLE'[ID]),'TABLE'[ID])<>SELECTEDVALUE('TABLE'[ID])))

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Popeye55 
Here is a sample file https://we.tl/t-dxOdnQphje

You need first to unpivot your data perhaps comfortably using power query

1.png2.png4.png5.png

BITomS
Resolver III
Resolver III

Hi @Popeye55 ,

 

I think the first thing you need to do is unpivot your data table as I don't see a date field to create your 'view over time'. Details on how to do this are here: https://support.microsoft.com/en-us/office/unpivot-columns-power-query-0f7bad4b-9ea1-49c1-9d95-f5882...

 

So your table would effectively look like this:

 

IDScoreDate
17501/01/2022 (or whatever Q1 start date is)
15401/04/2022 (or whatever Q2 start date is)
16701/07/2022 (or whatever Q3 start date is)
18601/10/2022 (or whatever Q4 start date is)
28001/01/2022 (or whatever Q1 start date is)
23601/04/2022 (or whatever Q2 start date is)
25401/07/2022 (or whatever Q3 start date is)
27501/10/2022 (or whatever Q4 start date is)
etc.etc.etc.

 

Then you could have one measure just as = AVERAGE('TABLE'[Score]) . This will update to show a single ID in your line chart when the ID has been selected from a slicer.

 

Your second measure for the overall average would be = CALCULATE(AVERAGE('TABLE'[Score]),ALL('TABLE'[ID])) . This will ignore any slicer selection made by a user.

 

If you want to exclude the user selected ID, the second measure above can be enhanced by using = CALCULATE(AVERAGE('TABLE'[Score]),ALL('TABLE'[ID]),'TABLE'[ID])<>SELECTEDVALUE('TABLE'[ID])))

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.

Top Solution Authors