cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
mahoneypat
Super User IV
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!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

8 REPLIES 8
v-yangliu-msft
Community Support
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.

v-yangliu-msft_0-1606091824540.jpeg

You can downloaded PBIX file from here.

 

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.

mahoneypat
Super User IV
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!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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"))

 

 

mahoneypat
Super User IV
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!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

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)

 

 

 

amitchandak
Super User IV
Super User IV

@Anonymous , Try like

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Anonymous
Not applicable

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

 

Thanks for the reply @

amit!

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

manikumar34
Super User I
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!
Did I answer your question? Mark my post as a solution!


Proud to be a Super User!




Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.