Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi,
I am trying to calculate median of a measure and then use both measure and median to create a calculated column. Appreciate any help on this.
I have the following view as below with some sample data
| Program Name | Team Name | Topic Name | Question | Answered Correctly |
| A | AA | W | ABC ? | Yes |
| B | BB | X | DEF ? | Yes |
| C | CC | Y | GHI ? | No |
| D | DD | Z | JKL ? | Yes |
Created a mesaure 'Correct Percentage' as below
Questions Answered Correctly = Calulate(CountRows(View), view(Answered Correctly) = "Yes")
Total =
Countrows(view)
Return Divide(Questions Answered Correctly, Total, 0)
I need to calculate Median of the above measure, i.e., Median of 'Correct Percentage' and then create a calculated column 'Category' with the following logic
If Correct Percentage >= Median then 'High Correct %' else 'Low Correct %'
The purpose of creating this 'Catogory' calculated column is to create a Matrix visual as below.
Topic Name | High Correct % | Low Correct % |
W | 76% |
|
X | 80% |
|
Y |
| 32% |
Z |
| 18% |
I am facing challenge in calculaing the "median" out of 'Correct Percentage' measure and then the 'Category' column to dislay in above format.
Any help would be really appreciated.
Thanks in Advance.
Regards,
Argha
Solved! Go to Solution.
Hi @Argha ,
The value is getting the same value on all the values because you are using the ALL statement that removes any filter context on your calculation making it program agnostic.
You need to make it with a ALLSELECTED option or a FILTER in order to get the values for the programs you need.
Can you give a more complete example on your needs, with the example you gave the result got correct however it only has for lines, and there is no information about dimension or relationships on your model wich make it difficult to perceive any other filter context that may impact the calculation.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em Português
Create a summarized table for your median calculation:
Program Summary =
SUMMARIZE(
'View',
'View'[Program Name],
"Correct %", [Correct Percentage]
)
Then create a measure for the median:
For your matrix, don't use a calculated column. Create this measure instead:
@Kedar_Pande - Thank you for your response.
I have already tried this way before and it doesn't work as expected.
Median is not calculated correctly. If both 'Correct percentage' and 'Median' is pulled in one table visual, the median value is same as the 'correct percentage' for a particular row.
For example, for Topic 'W' if the 'correct percentage' is 0.75, the median too shows as 0.75. However, the requirement is to have the median calculated considering all values of 'Correct Percentage' column
Hi @Argha ,
For this you need to use a variable with a temporary table something similar to this:
High Correct % =
Var temptable = ADDCOLUMNS( ALLSELECTED(Table[Topic]),"CorrectPercentage", [Correct Percentage])
)
Var medianvalue = MEDIANX ( temptable, [CorrectPercentage])
Return
IF([Correct Percentage] >= medianvalue, [Correct Percentage])
Low Correct % =
Var temptable = ADDCOLUMNS( ALLSELECTED(Table[Topic]),"CorrectPercentage", [Correct Percentage])
)
Var medianvalue = MEDIANX ( temptable, [CorrectPercentage])
Return
IF([Correct Percentage] < medianvalue, [Correct Percentage])
Be aware that depending on your model the part of the ALLSELECTED may need to be changed by a values or something similar.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsThank you for your quick response.
I quite did not get your statement "Be aware that depending on your model the part of the ALLSELECTED may need to be changed by a values or something similar."
From model perspective the sample view mentioned here acts as a fact table and is having a join with a dimension table.
Also, i did try creating 2 calculated columns as you suggested - 'High Correct %' and 'Low Correct %'. The former is not retrieving any value and while creating the later i get 'Circular Dependency' error.
Hi @Argha ,
What I have sent you is a measure not a column.
What I mean with the ALLSELECTED part is that this may need to be changed to another type of values selecting like ALL or VALUES.
Basically the measure is based on a virtual table where you calculate the median só that you can check if the % is above or below that.
If you want I can try and send you and examples.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @Argha,
Thank you for reaching out to Microsoft Fabric Community.
Thank you @MFelix and @Kedar_Pande for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa
Hi @Argha,
We wanted to kindly follow up to check if the solution provided by the user for the issue worked? Is your issue resolved? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa
Hi @v-achippa
Sorry for the late response. I got busy with other priorities.
Unfortunately both solutions didn't work for me.
1st solution @Kedar_Pande - I have already tried this myself before posting here. This doesn't work as per my requirement.
2nd solution @MFelix - It works partially with the below tweaked DAX logic.
Hi @Argha ,
The value is getting the same value on all the values because you are using the ALL statement that removes any filter context on your calculation making it program agnostic.
You need to make it with a ALLSELECTED option or a FILTER in order to get the values for the programs you need.
Can you give a more complete example on your needs, with the example you gave the result got correct however it only has for lines, and there is no information about dimension or relationships on your model wich make it difficult to perceive any other filter context that may impact the calculation.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsCheck out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!