Rolling total not calculating properly in PowerBI? - 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.

Related

HASONEFILTER SUMX total not calculating correctly

I am creating a Power BI measure that sums up averages so I have used the HASONEVALUE SUMX method but the total doesn't match what the actual sum would be if you just add up the information. Here is the measure:
And here is the results:
The total shows 31,654.25 but if you add up the rows you actually get 22,962.33. I am wondering if there is something wrong with my measure or if it is an issue of me not realizing it is pulling in additional information I'm not aware of.
This is calculating the average over all of the selected contracts and then summing that same value for each selected contract. (When you define a variable, it's treated as a constant in the remainder of the measure definition.)
Adding to #Alexis Olson, the average in a row is for the group, the total count is for entire datatable.
Below table is grouped by column A. Sum of averages is not equal to total average

I wanted to calculate monthly weighted average in 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

DAX: How to use TOTALYTD measure on date-filtered visual?

I have the following two measures:
Number of Contracts = COUNTROWS(Contracts)
Number of Contracts YTD = TOTALYTD([Number of Contracts];Calendar[Date])
The second measure works fine in most of my visuals, however I am having problems with a date-filtered matrix.
In the matrix I am filtering the visual by yesterday's month&day and I am showing the Number of Contracts YTD year by year (by placing Year in the matrix Rows).
When I do so, there is no difference between Number of Contracts YTD and Number of Contracts.
I tried nesting Calendar[Date] inside ALL, but it's not working (2020's data doesn't change, while earlier data disappears).
How can I handle it? Thanks

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

Quarterly sum of 3 month rolling average in Power BI (DAX or Power Query)

I have monthly results that I need to present as a 3 month rolling average, sometimes at a monthly level and sometimes as a sum of the 3 month rollling average for the quarter/year.
At the monthly level I've found the below formula to work well:
3-Mo Rolling Avg = CALCULATE([Market Performance], DATESINPERIOD(Calendar_Lookup[date], MAX(Calendar_Lookup[date]), -3, MONTH))
/ CALCULATE(DISTINCTCOUNT(Calendar_Lookup[Year_Month]), DATESINPERIOD(Calendar_Lookup[date], LASTDATE(Calendar_Lookup[date]), -3, MONTH))
But, when I show quarterly or annual results it shows one 3 month average instead of a sum of the 3 month averages for the period. How would you solve this?
The options I can see are:
Create a column in either Power Query or DAX that holds the 3 month averages so then I can SUM them as needed? Any advice on how to do this?
Figure out how to do a SUM of a measure. Any advice on how to do this?
Build a series of measures at the monthly, quarterly and annual level. Not a great solution as it doesn’t allow me to work fast when performing analysis because I have to be careful of pulling the right measure.
Any advice would be appreciated! Thanks!
But, when I show quarterly or annual results it shows one 3 month average instead of a sum of the 3 month averages for the period. How would you solve this?
Based on this part, it sounds like you need one of the iterator functions. In this case it sounds like a SUMX
The basic layout would be something along the lines of
Measure:= SUMX( VALUES(Calendar_Lookup[Year_Month] ) , [3-Mo Rolling Avg] )
This measure would first using VALUES function generate a distinct list of each [Year_Month]. It would then calculate using your existing [3-Mo Rolling Avg] for each [Year_Month] and then sum the results.