Replacing Missing Valuations with Adjusted Valuation - Finance/Accounting - powerbi

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.

Related

Creating a measure for specific requirement in Power Bi

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?

Running Total Measure calculating incorrectly

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.

Annual Percentage Change in Power BI

I am looking to calculate an annual percentage change, from today of a number of stock market indices. The data is a flat structure un-pivoted about the date column.
I am using a calendar with daily values extending to the end of the current year. My current code:
Ann pch =
VAR
__EarliestValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
SAMEPERIODLASTYEAR( 'Calendar'[Date]))
VAR __LastDateValue = SUM('Equity Markets (2)'[Value])
RETURN
CALCULATE(
DIVIDE(__LastDateValue,__EarliestValue)-1)
returns answers which are clearly incorrect.
I am very much a DAX/PBI novice.
DATA:
I also have a Calendar table:
I think that the metric is actually correct, what makes you believe it is not? Can you share your output?
What you need to do now is to put it into a context, ie put 'Calendar[Date]' into the desired visual (table for instance). If you don't do so, you'll calculate the total amount of value divided by the total amount of value for dates prior to one year, which might return quite a weird number. If you do so, on the other hand, you should get your YoY comparison.
Something to note - there are also quick measures:
Check them out, as one of them is actually YoY total, which you might want to try.

Power BI: Calculating STDEVX.P over 6-Month period

I am attempting to calculate the most recent 6-Month STDEVX.P (not including the current month; so in May 2017, I'd like to the STDEVX.P for periods Nov 2016 - Apr 2017) for sales by product in order to further calculate variation in sales orders.
The Sales Data is made up of daily transactions so it contains transaction date: iContractsChargebacks[TransactionDate] and units sold: iContractsChargebacks[ChargebackUnits], but if there are no sales in a given period, then there will be no data for that month.
So, for example, on July 1st, sales for the past 6 months were the following:
Jan 100
Feb 125
Apr 140
May 125
Jun 130
March is missing because there were no sales. So, when I calculate STDEVX.P on the data set, it is calculating it over 5 periods, when in fact there were 6, just one happens to be zero.
At the end of the day, I need to calculate STDEVX.P for the current six month period. If when pulling the monthly sales numbers, it only comes back with 3 periods(months), then it needs to assume the other 3 periods with a zero value.
I thought about manually calculating standard deviation instead of using the DAX STDEVX.P formula and found these 2 links as a reference on how to do so, the first being closest to my need:
https://community.powerbi.com/t5/Desktop/Problem-with-STDEV/td-p/19731
Calculating the standard deviation from columns of values and frequencies in Power BI...
I attempted to make a go of it, but still am not getting the correct calculation. My code is:
STDEVX2 =
var Averageprice=[6M Sales]
var months=6
return
SQRT(
DIVIDE(SUMX(
FILTER(ALL(DimDate),
DimDate[Month ID]<=(MAX(DimDate[Month ID])-1) &&
DimDate[Month ID]>=(MAX(DimDate[Month ID])-6)
),
(iContractsChargebacks[SumOfOrderQuantity]-Averageprice)^2),
months
)
)
*note: Instead of using date parameters in the code, I created a calculated column in the date table that gives each Month a unique ID, makes it easier for me.
Your question would definitely be easier to answer with more explanation regarding your model. E.g. how you defined [SumOfOrderQuantity] and [6M Sales], since a mistake there could definitely impact the final result. Also, knowing what the result you're seeing is vs. the result you expect would be helpful (using sample data).
My guess, however, is that your DimDate table is a standard date table (with one row per date), but you want standard deviation by month.
The FILTER statement in your formula limits the date range to the prior 6 full months correctly, but it will still have one row per date. You can confirm this in Power BI by going into the Data View, selecting 'New Table' under Modeling on the ribbon, and putting your FILTER statement in:
Table = FILTER(ALL(DimDate),
DimDate[MonthID]<=(MAX(DimDate[MonthID])-1) &&
DimDate[MonthID]>=(MAX(DimDate[MonthID])-6))
Assuming you have more than one day of sales for a given month, calculating the variance by day rather than by month is going to mess things up.
What I'd suggest trying:
Table = FILTER(SUMMARIZE(ALL(DimDate),[MonthID]),
DimDate[MonthID]<=(MAX(DimDate[MonthID])-1) &&
DimDate[MonthID]>=(MAX(DimDate[MonthID])-6))
The additional SUMMARIZE statement means that you only get one row for each MonthID, rather than 1 row for each date. If your [6M Sales] is the monthly average across all 6 months, and [SumOfOrderQuantity] is the monthly sum for each month, then you should be set to go calculating the variance, squaring, dividing by 6, and square rooting.
If you need to do further troubleshooting, remember you can put a table on your canvas with MonthID, SumOfOrderQuantity and [6M Sales] and compare the numbers you expect at each stage of the calculation with the numbers you're seeing.
Hope this helps.
I was facing a similar problem while trying to calculate the coefficient of variation (Std. /Mean) by SKUS from sales data. I could use the Pivot-Unpivot function in Power Query editor to to do away with the problem of months with missing sales:
1) Export the data with any calculated columns
2) Reimport the data so that the calculated columns are also available in the power query editor
3) Pivoted the data by months
4) Replaced null values with 0s
5) Unpivoted the data
6) Close and apply the query
7) Add a calculated column for the coefficient of variation using the formula 
CV = CALCULATE(STDEV.P(Table1[Value]),ALLEXCEPT(Table1,Table1[Product]))/CALCULATE(AVERAGE(Table1[Value]),ALLEXCEPT(Table1,Table1[Product]))
Thus zero sales for the missing months will also be considered both for Standard Deviation and Mean.

Power BI Percentage of Month passed

I would like to create a calculated column or measure that shows the time elapsed in any given month. Preferably as a percentage.
I need to be able to compare productivity (rolling total) over a month's period between different months.So creating a percentage of time passed in a month would put every month on a level playing field.
Is there a way to do this?
Or is there a better way to compare productivity between 2 months on a rolling basis?
EDIT
I am graphing sales on a cumulative basis. Here is a picture of my graph to demonstrate.[][
Ideally I would like to be able to graph another person's sales on the same graph for a different month to compare.
The problem is each month is different and I don't think power bi allows much customization of the axes.
So I figured a potential solution would be to convert months to percentages of time passed, create two separate graphs and place them on top of each other to show the comparison of sales.
Using percentages doesn't sound right here: one person's "productivity" in February will appear lower than another person's productivity in March just because February has 3 less days.
Just use [Date].[Day].
To answer the original question (even though it shouldn't be used for this), month progress percentage calculated column:
MonthProgress% =
var DaysinMonth = DAY(
IF(
MONTH(MyTable[date]) = 12,
DATE(YEAR(MyTable[date]) + 1,1,1),
DATE(YEAR(MyTable[date]), MONTH(MyTable[date]) + 1, 1)
) - 1
)
return MyTable[date].[Day]/DaysinMonth*100
Also check DAX functions PARALLELPERIOD and DATEADD.
This is the solution I settled on.
I customized the ranges for the x and y axes so they match.
For the y-axis, I simply put the range from 0 to 50+ our highest month.
For the x-axis, I created a column with the DAY function so I got a number assigned to each day of the month which allowed me to manually set the chart range from 0 to 31. I have asked another question on how to only get workdays.