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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
youssefm9
Helper I
Helper I

Calculating Average of Sales per account in a raw data

Hello All,

I would appreciate your support on the below topic. 

I want to calculate the average sales value by Customer and per account per month and for the whole year.

To calculate the average value per customer and month it is straightforward (sum of sales value / countdistinct customer) and the month can be selected in the filter, and for all year it will give the average by selecting all months.

However, what is not working with me is to create a formula that provides me result of sales value per number of accounts per month and for all year, whether we select a customer or not. It is very tricky. I have tried to use DAX but did not work. If it is simply sum of sales value / sum of # of accounts, I think that wont make sense if we calculate for the whole year for all accounts. Is there any solution for it?

 

 

 

CUSTOMERMONTHSALES VALUE# of ACCOUNTS
Customer AJan-2220010
Customer AFeb-2210011
Customer AMar-222012
Customer AApr-2240011
Customer AMay-2220012
Customer AJun-2222015
Customer AJul-2212014
Customer AAug-2233314
Customer ASep-2259314
Customer AOct-2289014
Customer BJan-229005
Customer BFeb-221006
Customer BMar-22506
Customer BApr-222007
Customer BMay-221007
Customer BJun-222007
Customer BJul-223007
Customer BAug-227007
Customer BSep-224008
Customer BOct-221007
Customer CJan-2220023
Customer CFeb-2230023
Customer CMar-2223023
Customer CApr-2234024
Customer CMay-2245024
Customer CJun-2275024
Customer CJul-2223024
Customer CAug-2212025
Customer CSep-2240024
Customer COct-2220025
1 ACCEPTED SOLUTION

Hi @youssefm9 

You can create a month column in table, then create two new table:

Table 2 = SUMMARIZE('Table',[CUSTOMER])
Table 3 = SUMMARIZE('Table',[month_Month])

Then create a new measure in table:

Average = SWITCH(TRUE(),ISFILTERED('Table 3'[month_Month])=FALSE()&&ISFILTERED('Table 2'[CUSTOMER])=FALSE(),CALCULATE(SUM([SALES VALUE])/SUM([# of ACCOUNTS]),ALLSELECTED('Table')),ISFILTERED('Table 2'[CUSTOMER])=TRUE()&&ISFILTERED('Table 3'[month_Month])=FALSE(),CALCULATE(SUM('Table'[SALES VALUE])/SUM('Table'[# of ACCOUNTS]),FILTER(ALLSELECTED('Table'),[CUSTOMER]=MAX('Table 2'[CUSTOMER]))),ISFILTERED('Table 2'[CUSTOMER])=FALSE()&&ISFILTERED('Table 3'[month_Month])=TRUE(),CALCULATE(SUM('Table'[SALES VALUE])/SUM('Table'[# of ACCOUNTS]),FILTER(ALLSELECTED('Table'),MONTH('Table'[MONTH])=MAX('Table 3'[month_Month]))),CALCULATE(SUM('Table'[SALES VALUE])/SUM('Table'[# of ACCOUNTS]),FILTER(ALLSELECTED('Table'),MONTH('Table'[MONTH])=MAX('Table 3'[month_Month])&&[CUSTOMER]=MAX('Table 2'[CUSTOMER]))))

create a measure to set if the measure can display:

if_display = SWITCH(TRUE(),ISFILTERED('Table 3'[month_Month])=FALSE()&&ISFILTERED('Table 2'[CUSTOMER])=FALSE(),1,ISFILTERED('Table 3'[month_Month])=FALSE()&&ISFILTERED('Table 2'[CUSTOMER])=TRUE(),IF(MAX('Table'[CUSTOMER])=MAX('Table 2'[CUSTOMER]),1,0),ISFILTERED('Table 3'[month_Month])=TRUE()&&ISFILTERED('Table 2'[CUSTOMER])=FALSE(),IF(MAX('Table'[month_Month])=MAX('Table 3'[month_Month]),1,0),IF(MAX('Table'[CUSTOMER])=MAX('Table 2'[CUSTOMER])&&MAX('Table'[month_Month])=MAX('Table 3'[month_Month]),1,0))

Then put the table 2 and table 3 columns to two slicers, and put the if_display measure to the table visual filter:

vxinruzhumsft_0-1673254590255.png

 

Output:

vxinruzhumsft_1-1673254606331.png

 

vxinruzhumsft_2-1673254618746.png

 

 

Best Regards!

Yolo Zhu

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

4 REPLIES 4
youssefm9
Helper I
Helper I

Hello Yolo.

Thanks for the reply. The solution does not work and this is the reason:

The number of accounts must not be commulative. If in Jan it was 5 accounts and Feb it is 6 accounts, then it has increased by 1 and not by 6. It is a subscribtion based sales value. So in PBI, if I filter customer A only, I want to see the average for full year (total sales value / total number of account (not commulative)). I can consider the average of the number of account during that year. Same goes for the number of account for all other customers.

So the best way is to first calculate the average sales per account for each month and then add these averages to see the total average sales per account.

Then if i want to see the total average for all the accounts, it will be average sales for each of the account divided by the number of accounts. 

Please let me know if it is not clear.

 

Thank you again. 

v-xinruzhu-msft
Community Support
Community Support

Hi @youssefm9 

You can create a measure:

Measure = CALCULATE(DIVIDE(SUM('Table'[SALES VALUE]),SUM('Table'[# of ACCOUNTS])),ALLSELECTED('Table'))

vxinruzhumsft_1-1672019759850.png

 

Best Regards!

Yolo Zhu

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

Hello Yolo,

Well it still does not do what is required.

The measure should be the sum of sales value / # of accounts 

# of accounts can be average of the full year or the # of accounts in last month.

What you did is you are dividing by commulative # of accounts, which should not be the case.

 

Hi @youssefm9 

You can create a month column in table, then create two new table:

Table 2 = SUMMARIZE('Table',[CUSTOMER])
Table 3 = SUMMARIZE('Table',[month_Month])

Then create a new measure in table:

Average = SWITCH(TRUE(),ISFILTERED('Table 3'[month_Month])=FALSE()&&ISFILTERED('Table 2'[CUSTOMER])=FALSE(),CALCULATE(SUM([SALES VALUE])/SUM([# of ACCOUNTS]),ALLSELECTED('Table')),ISFILTERED('Table 2'[CUSTOMER])=TRUE()&&ISFILTERED('Table 3'[month_Month])=FALSE(),CALCULATE(SUM('Table'[SALES VALUE])/SUM('Table'[# of ACCOUNTS]),FILTER(ALLSELECTED('Table'),[CUSTOMER]=MAX('Table 2'[CUSTOMER]))),ISFILTERED('Table 2'[CUSTOMER])=FALSE()&&ISFILTERED('Table 3'[month_Month])=TRUE(),CALCULATE(SUM('Table'[SALES VALUE])/SUM('Table'[# of ACCOUNTS]),FILTER(ALLSELECTED('Table'),MONTH('Table'[MONTH])=MAX('Table 3'[month_Month]))),CALCULATE(SUM('Table'[SALES VALUE])/SUM('Table'[# of ACCOUNTS]),FILTER(ALLSELECTED('Table'),MONTH('Table'[MONTH])=MAX('Table 3'[month_Month])&&[CUSTOMER]=MAX('Table 2'[CUSTOMER]))))

create a measure to set if the measure can display:

if_display = SWITCH(TRUE(),ISFILTERED('Table 3'[month_Month])=FALSE()&&ISFILTERED('Table 2'[CUSTOMER])=FALSE(),1,ISFILTERED('Table 3'[month_Month])=FALSE()&&ISFILTERED('Table 2'[CUSTOMER])=TRUE(),IF(MAX('Table'[CUSTOMER])=MAX('Table 2'[CUSTOMER]),1,0),ISFILTERED('Table 3'[month_Month])=TRUE()&&ISFILTERED('Table 2'[CUSTOMER])=FALSE(),IF(MAX('Table'[month_Month])=MAX('Table 3'[month_Month]),1,0),IF(MAX('Table'[CUSTOMER])=MAX('Table 2'[CUSTOMER])&&MAX('Table'[month_Month])=MAX('Table 3'[month_Month]),1,0))

Then put the table 2 and table 3 columns to two slicers, and put the if_display measure to the table visual filter:

vxinruzhumsft_0-1673254590255.png

 

Output:

vxinruzhumsft_1-1673254606331.png

 

vxinruzhumsft_2-1673254618746.png

 

 

Best Regards!

Yolo Zhu

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

 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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