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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Syndicate_Admin
Administrator
Administrator

Calculated Column Subject to Context (Z-Score Calculation)

Hello

I've been trying to create a calculated column to get the Z-Score of a piece of data segmented by a variable.

I have managed to arrive at this formula (which I leave at the end), which gives me the Z-scores of the "Population" column based on the "Language spoken" column (there are a large number of rows that refer to this data depending on the region, country, etc.)

However, I can't get the column to be subject to context, as I apply other filters in the table (filter as a visual) and the calculations don't change. That is, I want to filter by another field, in this case, "Country", to see the Z-scores of each "Region" and that these Z are recalculated for the specific country (and not calculated on the total sample, which is what happens to me now).

z score =
were _variable = CALCULATE(SELECTEDVALUE(DB[Language spoken]))
were _Average = CALCULATE(AVERAGE(DB[Population]),FILTER(ALL(DB),DB[Language spoken]=_variable))
were _DesvT = CALCULATE(STDEV. S(DB[Population),FILTER(ALL(DB),DB[Language spoken] =_variable))
return
DIVIDE(DB[Population]-_Average, _DesvT)
Thanks a lot
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Syndicate_Admin 

 

"ALL" does not apply the slicer, you can try changing it to "ALLSELECTED". "ALLSELECTED" will retain the slicer filter and remove other filters.

 

Please try the following:

 

Create a measure.

Measure = 
var _Average = 
    CALCULATE(
        AVERAGE('Table'[Population]), 
        FILTER(
            ALLSELECTED('Table'),
            'Table'[Language spoken] in {[Language spoken]}
        )
    )
var _DesvT = 
    CALCULATE(
        STDEV.S('Table'[Population]), 
        FILTER(
            ALLSELECTED('Table'), 
            'Table'[Language spoken] in {[Language spoken]}
        )
    )
RETURN DIVIDE(SELECTEDVALUE('Table'[Population]) - _Average, _DesvT)

 

Here is the result.

vnuocmsft_0-1706169195132.png

 

vnuocmsft_1-1706169213287.png

 

Regards,

Nono Chen

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

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Syndicate_Admin 

 

"ALL" does not apply the slicer, you can try changing it to "ALLSELECTED". "ALLSELECTED" will retain the slicer filter and remove other filters.

 

Please try the following:

 

Create a measure.

Measure = 
var _Average = 
    CALCULATE(
        AVERAGE('Table'[Population]), 
        FILTER(
            ALLSELECTED('Table'),
            'Table'[Language spoken] in {[Language spoken]}
        )
    )
var _DesvT = 
    CALCULATE(
        STDEV.S('Table'[Population]), 
        FILTER(
            ALLSELECTED('Table'), 
            'Table'[Language spoken] in {[Language spoken]}
        )
    )
RETURN DIVIDE(SELECTEDVALUE('Table'[Population]) - _Average, _DesvT)

 

Here is the result.

vnuocmsft_0-1706169195132.png

 

vnuocmsft_1-1706169213287.png

 

Regards,

Nono Chen

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

 

 

Syndicate_Admin
Administrator
Administrator

Hello

Here is an example of how the data would be distributed.

RegionCountryLanguage spokenPopulation
EuropaSpainSpanishxxxx
EuropaSpainCatalanxxxx
EuropaSpainBasquexxxx
EuropaSpainCatalanxxxx
AmericaArgentinaSpanishxxxx
AmericaChileSpanishxxxx
AmericaBrazilPortuguesexxxx
AmericaDominican Republic Spanishxxxx
AmericaDominican Republic Frenchxxxx
Ritaf1983
Super User
Super User

Hi @Syndicate_Admin 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors