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.
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
Solved! Go to Solution.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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.
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.
Did you try the expression I provided? That should give you the avg pct of overall sales.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe 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"))
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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)
@Anonymous , Try like
divide(calculate(Sum(Table[Sales])),calculate(Sum(Table[Sales]),allexcept(Table,Table[Month])) )
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
@Anonymous ,
Try something like this.
SUM (Table[Product]) / Calculate(SUM (Table[Product]),All(Table[Product]))
Regards,
Manikumar
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
100 | |
78 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
94 | |
84 | |
67 |