I have a dataset containing costs by date incurred, cost type, and location. Cost type can be either Actual or Estimate and location is A, B, and C. I have a measure that calculates running total of Cost by Date Incurred. (Just for background, if the Date Incurred is in the future, the Cost type is entered as Estimate, but if the Date Incurred is in the past, the Cost Type is entered as Actual. It gets updated daily.) When I view my Cost Running Total measure, it calculates correctly. However, when I filter for Location, it resets the calculation when the Cost Type switches from Actual to Estimate.
This is the DAX I'm currently using:
Final Cost running total in Date Incurred =
CALCULATE(
SUM('data_tbl'[Final Cost]),
FILTER(
ALLSELECTED(data_tbl[Date Incurred]),
ISONORAFTER('data_tbl'[Date Incurred], MAX('data_tbl'[Date Incurred]), DESC)
)
)
And this is the expected vice actual results:
Note that when I remove the filter for Location A, Power BI calculates the numbers in Column E, but when I filter for Location A using a slicer, Power BI switches to calculating the numbers in column F. Is there any way to work around this so that Power BI won't add the Cost Type as a filter?
EDIT: There is a third cost type in the data set. I need to be able to filter out that cost type and display the Actual and Estimate costs, but I don't want the calculation to reset when the cost type switches between the two cost types that I have selected to view.
Related
I have a date set of with the relevant columns; Investment ID, Effective Date, Reported Valuation, Fundings, and Distributions.
Investments can report valuations on a either a Quarterly, Semi Annual, or Annual Basis - typically on the last day of the respective period. Therefore in a given year each investment can have a different number of valuation entries. You are always interested in having the latest valuation for any measured period or interval.
During a given period, there can be any number of fundings (where you add cash to an investment) or Distributions (where you receive cash from an investment). These can happen on any day during the year.
Transaction history table:
I would like this data to be able filter into a matrix that can drill into Monthly, Quarterly, and Yearly levels. The issue is that when I pull the most recent valuation for a given period using the below function:
Most Recent End Period Rep Valuation = CALCULATE (
SUM ( 'TH'[ReportedValuation] ),
LASTDATE ( 'TH'[Effective Date] ),
'TH'[Valuation Bool] = 1 )
There are missing valuations for each respective investment and date (which occurs more frequently as you drill down the date hierarchy).
When you reach the month level, all investments have missing valuations in at least the first and second months of the quarter since none report that frequently.
Matrix with All Investments:
Matrix with only Investment A:
Matrix with only Investment B:
Matrix with only Investment C:
For the sake of tracking the valuation at any given time in the year, we use an Adjusted Value. An Adjusted Value is a way to estimate the financial value of the asset between its reporting dates. Its measured by taking:
(The last reported valuation)
+
(Fundings that have occurred between the date of the last reported valuation and the current point of measurement)
-
(Distributions that have occurred in the same period as the Fundings)
Using this calculation I can measure the intermediate valuation between periods to estimate my value up to the next reported valuation.
To illustrate: in the case of Investment C, it would be adding the running total of the fundings and distributions between 12/31/2020 and 12/31/21. that adjustment would have to happen for each investment for all the intervals its missing a valuation for.
So for Investment A, it would be measuring the adjusted valuation for the second and third month. For Investment B, it would be measuring for the next five months.
So I need to find a way to use or generate an adjusted value for the blanks in the matrix. I've considered the following solutions:
Use a measurement so that I can SWITCH() to use the most recent reported value() function OR use a new measurement that would calculate the correct adjusted value for all levels of the date hierarchy - the issue I've had with this is solving for each group by Investment ID before aggregating through the Most recent function.
Creating a new table that will have adjusted values calculated through a PowerQuery; my PowerBI skills are very limited so would love help on solving this! Mostly experienced in Excel and R.
PS: this a very simplified version of the data set I'm using. My other data set has more than 500 investments with 20 years of data (all active for different periods with no 'end date' value). So a measurement solution would be preferred so my data aggregates dynamic.
I am facing this below issue.
I need to calculate Budget variance % which is ((Actual Cost -Budget)/Budget)*100. So for that we need to sum the actual cost for a particular month say, January,2021 and have to subtract budget for that particular month(Jan) only, for each costcenter , and we have got only single budget for every month for each cost center whereas we have actual cost for each day in a month ,for each cost center ,which will be summed up. Actual cost and budget are coming from 2 diff tables say A & B respectively. Table A is having columns named Cost center,Date,ActualCost,OrderID. Table B consists of columns named, Cost center,Date,Budget. Date column is having diff set of dates in two diff tables A & B. So, when I am trying to do the required calculation, its throwing error . Can anyone please help me with the steps to follow to calculate this Budget variance?
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 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")
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.