I wanted to calculate monthly weighted average in powerBI - powerbi

I have a table that has PIMS code of crudes and first day of the month, its cost(Rs/MT) and quantity Thousand MT to be processed.
I need to calculate the weighted average of cost(Rs/MT) based on PIMS code and for that month only.
In the table, as you can see there are double entries of PIMS code with different quantity and price but with the same date and that difference needs to be considered while doing the average so I want to get a weighted average.

You can create a Weighted Average measure using the Quick measure functionality. You can do a basic google search for this as well.
Here is the documentation for creating a Quick Measure.

The following should work (Assuming your table is called 'Data')
Weighted Avg:=
VAR TotalUnits=SUM(Data[Quantity (TMT)])
VAR TotalCost=SUMX(Data,Data[cost(Rs/MT)]*Data[Quantity (TMT)])
RETURN
TotalCost/TotalUnits
Screenshot below to show examples with some dummy data

Related

Rolling total not calculating properly in PowerBI?

I am trying to put together a rolling monthly total measure in PowerBI but my measure is not even calculating
My data is similar to below
My data
Data Model
I have made my calculation as follows:-
Rolling Annualized Revenue =
CALCULATE(
[Annual Revenue],
FILTER('Calendar Lookup',
'Calendar Lookup'[Date]
<=MAX('Calendar Lookup'[Date])))
Edit: I just realized I copied the wrong formula altogether here
For whatever this is not working at all and yields just the annual revenue not a rolling sum
Calc Result in a matrix
I determined that I needed to add the year to the row context in order for my calculation to work properly.

Power BI: Categorize customers based on measures

I have a list of customers that I wish to categorize based on two criteria: Share of total income and average time from due date to payment date.
I have a table with customer transactions that I can use to calculate these two criteria.
The solution I currently have is to use calculated columns in the customer table:
Sum of invoiced amount per customer/Total sum all customers = Share of total income
Average number of days per customer
I then use IF-functions to categorize these metrics into Big/Medium/Small customers, and Good/Medium/Bad payers.
Next I use a Matrix visualization to see number of customers for each category (Big customer/Good payer, Small Customer/Medium payer, and so on).
The problem I get is that the outcome of this is static, and they doesn't change if I use slicers to get only transactions from one year, or for only one of our companies.
Can I instead use measures for this, and get a dynamic Matrix visualization?
You need to use measures for this. It is a common pattern known as dynamic segmentation. You can read how to implement it here: https://www.daxpatterns.com/dynamic-segmentation/

POWER BI the same value for a column repeated multiple times(up to 24 times), want it just once, how to fix

I got an online campaign data, and there is an issue that the 'budget' for each day/campaign is the same but each time a campaign happens the budget repeats.
for example:
I want to build a table, that shows the avg budget of each campaign for these two days, as well as the total (also avg) at the bottom, like this:
Create a measure that calculates the Average() of the budget column.
Then create a visualisation (table or matrix) and use the campaign field along with the measure.

Power BI YTD Calculations

I am trying to do some time based calculations on my budgeting data but struggling to understand where I'm going wrong or if my data structure would even support what I'm trying to do.
As per the image above, this is my raw data. ie. A monthly budgeted and actual total for each cost centre that is being imported from an excel spreadsheet.
I am trying to calculate a YTD budget and YTD Actual figure per cost centre based on the monthly totals. Ideally I would like all of this data displayed in a table that I can then use slicers to segment/pivot.
When using the CALCULATE() function in a measure, I am unable to select my cell value for each date and cost centre.
eg.
YTD Actual = CALCULATE( [Actual MTH] , DATESYTD('Dates'[Date], "30/6"))
returns the error
The value for 'Actual MTH' cannot be determined. Either 'Actual MTH'
doesn't exist, or there is no current row for a column named 'Actual
MTH'.
Any assistance with getting a greater understanding of the issue here would be appreciated.
Thanks
Try something like this for your measures:
YTD Actual = TOTALYTD(sum([Actual MTH]),'Dates'[date],ALL('Dates'[date]),"30/6")

Measure to sum another aggregated measure's data

I am working on a report that has data by month. I have created a measure that will calculate a cost per unit which divides the sum of dollars by the sum of production volume for the selected month(s):
Wtd Avg = SUM('GLData - Excel'[Amount])/SUM('GLData - Excel'[Production])
This works well and gives me the weighted average that I need per report category regardless of if I have one or multiple months selected. This actual and budget data is displayed below:
If you take time to total the actual costs you get $3.180. Where I am running into trouble is a measure to sum up to that total for a visual (This visual does not total sadly). Basically I need to sum the aggregated values that we see above. If I use the Wtd Avg measure I get the average for the total data set, or .53. I have attempted another measure, but am not coming up with the correct answer:
Total Per Unit Cost = sumX('GLData - Excel','GLData - Excel'[Wtd Avg])/DISTINCTCOUNT('GLData - Excel'[Date])
We see here I return $3.186. It is close, but it is not aggregating the right way to get exactly the $3.180:
My Total Per Unit Cost formula is off. Really I am simply interested in a measure to sum the post aggregated Wtd Avg measure we see in the first graph and total to $3.180 in this example.
Here is my data table:
As you probably know already, this is happening because measures are dynamic - if you are not grouping by a dimension, they will compute based on the overall table. What you want to do is to force a grouping on your categories, and then compute the sum of the measure for each category.
There are 2 ways to do this. One way is to create a new table in Power BI (Modeling tab -> New Table), and then use a SUMMARIZE() calculation similar to this one to define that table:
SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg])
Unfortunately I do not know your exact column names, so you will need to adjust this calculation to your context. Once your new table is created, you can use the values from that table to create your aggregate visual - in order to get the slicers to work, you may need to join this new table to your original table through the "Manage Relationships" option.
The second way to do this is via the same calculation, but without having to create a new table. This may be less of a hassle. Create a measure like this:
SUMX(SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg]),[Wtd Avg])
If this does not solve your issue, go ahead and show me a screenshot of your table and I may be able to help further.