cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## Calculate individual month wise product sales and then divide it by number of months? Pls help me

I have the following scenario

Product        Sales           Month

A                  100              Jul

B                  200              Jul

C                  300              Jul

A                  200              Aug

B                   100             Aug

C                   50             Aug

Now, I want the following output:

First it should divide the product sales/overallproduct sales for july and then it should do the same for august

After that, i want both the result values to be divided by number of months, in this case 2 months.... as i select july and august

How to achieve this in DAX?

=> SUM ([Product] 'A') For july / SUM([Product]'A'+'B'+'C') for july

100/600

=0.16

=>SUM ([Product] 'A') For August/ SUM([Product]'A'+'B'+'C') for August

200/350

=0.57

Finally, these two values (0.16+0.57) should be divided by 2 months

=0.16+0.57

=0.73/2

FINAL OUTPUT Needed=0.36

Pls help me guys how to achieve this

1 ACCEPTED SOLUTION
Super User IV

Please try this measure expression in a table visual with the Product column.

AvgMonthly =
AVERAGEX (
VALUES ( Table[Month] ),
DIVIDE (
CALCULATE (
SUM ( Table[Sales] )
),
CALCULATE (
SUM ( Table[Sales] ),
ALL ( Table[Product] )
)
)
)

Regards,

Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

8 REPLIES 8
Community Support

Hi  @Anonymous

Here are the steps you can follow：

1. Create calculated table.

``````Table 2 =
SUMMARIZE('Table',
[Month],
"sum_A",CALCULATE(SUM('Table'[Sales]),FILTER('Table',[Product]="A")),
"sum",SUMX(FILTER('Table','Table'[Month]=EARLIER('Table'[Month])),'Table'[Sales]))``````

2. Create calculated column.

``````Divide =
DIVIDE([sum_A],[sum])

Average =
AVERAGE('Table 2'[Divide] )``````

3. Result.

Best Regards,

Liu Yang

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

Super User IV

Did you try the expression I provided?  That should give you the avg pct of overall sales.

Regards,

Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

Anonymous
Not applicable

Sorry, actually I have used this logic @mahoneypat :

Average % =

AVERAGEX(VALUES('Date'[MONTH]),
IFERROR(
CALCULATE(sum(Table[SALES])
/
sumx(

ALL('TABLE'[Product]),

CALCULATE(SUMX(Table,Table[sales]))
)
,"NA"))

Super User IV

Please try this measure expression in a table visual with the Product column.

AvgMonthly =
AVERAGEX (
VALUES ( Table[Month] ),
DIVIDE (
CALCULATE (
SUM ( Table[Sales] )
),
CALCULATE (
SUM ( Table[Sales] ),
ALL ( Table[Product] )
)
)
)

Regards,

Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

Anonymous
Not applicable

Thank you for the reply @mahoneypat

I used this logic in the following way:

Average % =
IFERROR(
sum(Table[SALES])
/
sumx(

ALL('TABLE'[Product]),

CALCULATE(SUMX(Table,Table[sales]))
)
,"NA")

But,

When i select two months in the slicer, dax is only summing up the sales value for july and august, it is not doing the average of (summed up julay and aug sales value)

Super User IV

@Anonymous , Try like

divide(calculate(Sum(Table[Sales])),calculate(Sum(Table[Sales]),allexcept(Table,Table[Month])) )

Proud to be a Super User!

Anonymous
Not applicable

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

amit!

I am getting this error when i try to do implement the logic

Super User I

@Anonymous ,

Try something like this.

SUM (Table[Product]) / Calculate(SUM (Table[Product]),All(Table[Product]))

Regards,

Manikumar

If this helps, Appreciate your KUDOS!

Proud to be a Super User!

Announcements