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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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

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

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


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

@Anonymous , Try like

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

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

@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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.