cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

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
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
Microsoft
Microsoft

Hi  @ramz21 

 

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.

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


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

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

@ramz21 , 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!

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

Super User I
Super User I

@ramz21 , 

 

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
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

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.

Top Solution Authors
Top Kudoed Authors