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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Nepal101
Helper III
Helper III

Calculating average based on different column.

Hello Everyone, 
I hope to get some help on this DAX or any idea on how to solve this issue. Below is just an example of the data. 
I created a column that would do some average 

Avgwithincolumn = Calculate( AVERAGEX('D-with dates','D-with dates'[Avg), ALLEXCEPT('D-with dates','D-with dates'[Customer],'D-with dates'[Year],'D-with dates'[accountnumber],'D-with dates'[group]))
when using this calculation it gives 19 instead of 18 value. so when we add the avg coulmn= 89/5=18 which is the correct value but in the average calculated column I see 19. I am not sure what the reason could be. for other customers the average is correct 
If anyone could help me that would be great.
Customersalespersongroupaccountnumberavgavg calculatedcolumn
AB001231319
AB001231619
AB001231719
AB001232119
AB001232219
1 ACCEPTED SOLUTION

@Nepal101 

var c = table_name[Customer]
var s = table_name[salesperson]
var g = table_name[group]
var an = table_name[account number]

return
averagex ( 
     filter(
        summarize( 
           table_name,
            table_name[Customer],
            table_name[salesperson],
            table_name[group],
            table_name[account number],
           table_name[avg]

        ),
table_name[Customer] = c && 
table_name[salesperson] = s &&
table_name[group] = g &&
table_name[account number] = an 
),

table_name[avg]

)

 

 

let me know if it works for you . 

 

 

 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

 

 

 

CustomerSalespersonGroupaccount numberavgDate

 

View solution in original post

7 REPLIES 7
Nepal101
Helper III
Helper III

Hello @Daniel29195  and @v-rzhou-msft 

 

 

Thank you for the reply I don't think I have an option to attach the pbix file. Please let me know how can I attach the PBIX file. 
so when I looked at the data again on the data view there were numbers duplicated due to the dates so that was the reason I was getting 19. as there was 39 count of rows and 733 sum = 18.79 so in this case is there a way to calculate average by creating distinct count and distinct sum so the value could be 5 distinct count rows and 89 sum. I hope the below example can be helpful. Please let me know how can I achieve this. The data is such that I can't remove the duplicates I need that for other reports. Thank you again for your time and for looking into this.

CustomerSalespersonGroupaccount numberavgDate 
AB001021301/22/2023 
AB00102162/22/2023 
AB00102174/22/2023 
AB00102218/24/2023 
AB00102229/22/2023 
AB001021301/22/2023 
AB00102162/22/2023 
AB00102174/22/2023 
AB00102218/24/2023 
AB00102229/22/2023 
AB001021301/22/2023 
AB00102162/22/2023 
AB00102174/22/2023 
AB00102218/24/2023 

@Nepal101 

var c = table_name[Customer]
var s = table_name[salesperson]
var g = table_name[group]
var an = table_name[account number]

return
averagex ( 
     filter(
        summarize( 
           table_name,
            table_name[Customer],
            table_name[salesperson],
            table_name[group],
            table_name[account number],
           table_name[avg]

        ),
table_name[Customer] = c && 
table_name[salesperson] = s &&
table_name[group] = g &&
table_name[account number] = an 
),

table_name[avg]

)

 

 

let me know if it works for you . 

 

 

 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

 

 

 

CustomerSalespersonGroupaccount numberavgDate

 

Thank you so much this worked @Daniel29195  

Nepal101
Helper III
Helper III

Hello @Daniel29195
Thank you for the reply. 
I did removed the year but still it is showing me 19  is there anything that I should try. I tried removing each column and running it but no luck 

Nepal101_0-1707191232634.png

 

Hi @Nepal101 ,

 

I have a test by code as below. 

My Code = 
CALCULATE (
    AVERAGEX ( 'D-with dates', 'D-with dates'[Avg] ),
    ALLEXCEPT (
        'D-with dates',
        'D-with dates'[Customer],
        'D-with dates'[accountnumber],
        'D-with dates'[group]
    )
)

I create a measure and a calculated column to have a test.

vrzhoumsft_1-1707205537821.png

vrzhoumsft_0-1707205401285.png

I get the same result as  Daniel29195, please share a sample with us, this will make it eaiser for us the find the solution.

You also can download my attatchment to compare my data model with yours.

 

Best Regards,
Rico Zhou

 

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

 

@Nepal101 

 

can you share your file so i can take a look ? 
best regards

 

Daniel29195
Super User
Super User

@Nepal101 

 

Daniel29195_0-1707177361185.png

 

i just removed the year in allexcept . 

im not sure if this is what you want . but it returns the desired number .

 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.