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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Need to get average by state and bucket filters.

I have a table with average of new patients for each account, now I need a average of new patients in state level, so for accounts in one state should average by state to be same. This is get a baseline to compare each account. Please find the table below. 

Billy597_0-1707420834603.png

I want the DAX for the last Average Newpatient by state column, currently I have brought it by SQL querying, but going forward I would need a dax to do this. 
Something I tried but isn't showing right numbers: 

StateLevelAverageNewPatientsPerLocation =
VAR TotalNewPatientsInState =
    CALCULATE(
        SUM('NewPatient'[NewPatientsCount]),
        ALL('NewPatient'[AccountId])
    )
VAR TotalLocationsInState =
    CALCULATE(
        SUM('NewPatient'[LocationCount]),
        ALL('NewPatient'[AccountId])
    )
RETURN
    DIVIDE(
        TotalNewPatientsInState,
        TotalLocationsInState,
        BLANK()
    )



2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

Depending on the information you provided, please follow this step below:
1.Add new measure.

StateLevelAverageNewPatientsPerLocation =
VAR TotalNewPatientsInState =
    CALCULATE (
        SUM ( 'NewPatient'[NewPatientsCount] ),
        ALLEXCEPT ( 'NewPatient', 'NewPatient'[Buckets] )
    )
VAR TotalLocationsInState =
    CALCULATE (
        SUM ( 'NewPatient'[LocationKey] ),
        ALLEXCEPT ( 'NewPatient', 'NewPatient'[Buckets] )
    )
RETURN
    DIVIDE ( TotalNewPatientsInState, TotalLocationsInState, BLANK () )

Final output:

 

vyifanwmsft_0-1707445534942.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

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

Anonymous
Not applicable

Thanks for the reply, but [bucket] and [state] columns are both in another table called 'Account ids', and 'New patient' table is joined by [Account id] field. Please find the pbix file here: SALESCopy.pbix.

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