I've got a measure called _CumulativeBudget that has the following formula:
_CumulativeBudget = CALCULATE(SUM('Sheet1'[2017 Budget]), FILTER(ALLSELECTED('Sheet1'), 'Sheet1'[Imp Month]<=MAX('Sheet1'[Imp Month])))
Which you can see as the line in the following chart:
The problem is that each of those bars represent the END of a cash flow. For example, there is a project that was allocated $0.2M in budget whose "Imp Month" (Impact Month) is March. But really, the team was given all $0.2M at the beginning of the year and probably spent about 1/3 of that money in Jan, 1/3 in Feb, and 1/3 in Mar.
So if a project has an Imp Month of X, I'd like the cumulative measure to sum 1/X of it's budget in Jan, 1/X in Feb, etc.
Is this something that's fairly doable in a measure? If not, I may just go with a straight line approximation--e.g. if the year-end number is $1.9M then the budget is approximately 1/12th of that each month.
Thanks in advance for any assistance, guys!
I started with some mock data that looks like this.
1) I created a table of months.
Months = SELECTCOLUMNS(
FILTER(
CALENDAR(DATE(2017, 1, 1), DATE(2017, 12, 31)),
DAY([Date]) = 1
),
"Month", [Date]
)
2) I created a calculated table that crossjoined the two tables and filtered it down based on comparing Imp Month to the Month from the month table. At the same time, I limited down the columns and created a new column for the monthly budget.
BudgetExpanded = SELECTCOLUMNS(
FILTER(
CROSSJOIN(Sheet1, Months),
YEAR(Sheet1[Imp Month]) = Months[Month].[Year] &&
MONTH(Sheet1[Imp Month]) >= Months[Month].[MonthNo]
),
"Project", Sheet1[Project],
"Imp Month", Months[Month].[Date],
"Monthly Budget", CALCULATE(
MAX(Sheet1[2017 Budget]) / MONTH(MAX(Sheet1[Imp Month])),
FILTER(Sheet1,
Sheet1[Project] = EARLIER(Sheet1[Project])
)
)
)
3) I created relationships between the tables.
4) I added your cumulative measure to the new table and updated it for the Monthly Budget column.
CumulativeBudget = CALCULATE(
SUM(BudgetExpanded[Monthly Budget]),
FILTER(
ALLSELECTED(BudgetExpanded),
BudgetExpanded[Imp Month] <= MAX(BudgetExpanded[Imp Month])
)
)
5) I created a combo chart similar to yours with the original 2017 Budget and the new CumulativeBudget (black line is the new measure; red line is your original measure).
Related
I am trying to create a single measure that will calculate a date average, depending on the drill down on a time barchart.
The bar chart has 5 time pieces in the hierarchy. Year - Quarter - Month - Week -Day
As I drill through the bar chart, I want a measure that will dynamically calculate the Yearly Avg - Quarterly Avg - Monthly Avg, Weekly Avg, Daily Avg.
For example, lets say the barchart is on the Year Level and displaying 4 bars representing 2016-2019. The vale of the measure would be COUNT(UnitID) / 4 because there are 4 bars currently displayed on the X axis.
Lets drill into 2018 to the month level. There are 12 bars representing Jan-Dec. The value of the measure would be COUNT(2018 UnitIDs) / 12 because there are 12 bars currently displayed on the X axis.
Lets drill into 2019 to the month level. There are only 10 bars representing Jan-Oct. The value of the measure would be COUNT(2019 UnitIDs) / 10 because there are only 10 bars currently displayed on the X axis.
Finally, lets not drill down, but just expand the hierarchy from year to month. We go from the yearly view showing 4 bars to the monthly view showing 12. But the Jan total is the sum of 2016Jan + 2017Jan + 2018Jan + 2019Jan. The measure needs to interpret this as COUNT(All UnitIDs) / 12 because there are 12 months currently displayed on the X Axis.
I'm basically trying to figure out how to create a measure that counts whatever number of values are on the X axis at any given time.
Thank you all for your advice and feedback. I'm really looking forward to testing your responses and seeing if they work!
It sounds like you are looking for a way to show the same value for each year, quarter, month, etc.
I wonder how this would make sense as a visual, but if that is the case, your measure would be something like this.
Average Count UnitIDs in Drilldown Periods =
-- At which level the report is drilled down?
VAR CalendarDrilldownLevel =
IF(ISFILTERED('Calendar'[Day]), "Day",
IF(ISFILTERED('Calendar'[Week]), "Week",
IF(ISFILTERED('Calendar'[Month]), "Month",
IF(ISFILTERED('Calendar'[Quarter]), "Quarter",
IF(ISFILTERED('Calendar'[Year]), "Year", "None")))))
-- Total count of UnitIDs in the entire period
VAR TotalCount = CALCULATE([Count of Unit IDs], ALLSELECTED('Calendar'))
-- Number of years, quarters, months, etc. based on the drilldown level
VAR CountOfPeriods = CALCULATE(
SWITCH(
CalendarDrilldownLevel,
"Year", DISTINCTCOUNT('Calendar'[Year]),
"Quarter", COUNTROWS(
DISTINCT(
SELECTCOLUMNS(
'Calendar',
"Year", 'Calendar'[Year],
"Quarter", 'Calendar'[Quarter]
)
)
),
"Month", COUNTROWS(
DISTINCT(
SELECTCOLUMNS(
'Calendar',
"Year", 'Calendar'[Year],
"Quarter", 'Calendar'[Quarter],
"Month", 'Calendar'[Month]
)
)
),
-- Similar lines follow for weeks, days, and in case of no drill down.
),
ALLSELECTED('Calendar')
)
RETURN DIVIDE(TotalCount, CountOfPeriods)
Maybe you are trying this to show average line in the visual? In that case, you can just define a simple measure like COUNT('Your Table'[UnitID]) and add an average line in column chart visual setting. (You can find that in Analytics section)
Create a measure to compare forecast vs sales in power BI.
The logic is that at the beginning of Jan. 2018 it is forecasted the sales for the whole year and the amount of pcs sold in Jan. 2018 is only known in Feb. 2018 (next month's file). As an example, we are in Nov. 2018 and it is known how many pcs were sold in the previous months. I want to create a table to compare forecast vs sales.
My dataset looks like the figure below. It is marked in red the historical data.
An example of a power BI matrix that I am trying to create by dividing forecast by sales
It looks like you need to normalize your data source. This may look something like:
Now you can create some measures. Create a Forecast Qty measure:
Forecast Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Forecast"
)
A Sold Qty measure:
Sold Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Sold"
)
And a Sales % Forecast Measure:
Sales % Forecast:=DIVIDE (
[Sold Qty],
[Forecast Qty],
BLANK()
)
Now you can lay out your visualisation as you choose. For example:
I am working in POWER BI and trying to calculate a DAX expression for the rolling total of the previous month. I have a filter where I select a certain month, I would like to calculate the rolling total for the previous month.
Below is the calculation that works perfectly to calculate the rolling total for the selected date range.
How can I calculate the previous months rolling total?
Rolling_Total_Current_Month = CALCULATE(
SUM(SalesInvoice[Sales])
,FILTER(ALLSELECTED(SalesInvoice), (SalesInvoice[Date]) <= MAX(SalesInvoice[Date])))
Here is a sample of my data, I have sales per day, for multiple categories, (in fact i have a couple more columns of details but this is simplified)
Date Day Amount Category
1/1/2016 1 100 A
1/1/2016 1 120 B
1/1/2016 1 90 C
1/2/2016 2 500 A
1/2/2016 2 321 B
1/2/2016 2 143 C
So far I have come up with an equation to solve the rolling total, but when I try to slice is and view the rolling total of a single category it does not work for the previous month. I just keeps the original rolling total for the previous month.
Here is the equation for the rolling total previous month that works. But does not recalculate a rolling total for the previous month once sliced based on category.
PREVIOUS_MONTH_ROLLING_TOTAL =
CALCULATE(
[Current Sales]
,FILTER(
ALL( Orders )
,Orders[MonthNumber] = MAX( Orders[MonthNumber] ) - 1
&& Orders[Day] <= MAX( Orders[Day] )
)
)
I have solved how to get the previous months rolling total.
You must do three things. First create a Month Number column in your data sheet (this is used as an integer to subtract 1 month from). You must also create a days column as well.
Then create a measure for Current Sales or whatever your value is.
Create a measure for the current month sales
Current Sales = SUM(Orders[Amount])
Then this equation.
PREVIOUS_MONTH_ROLLING_TOTAL =
CALCULATE(
[Current Sales]
,FILTER(
ALL( Orders )
,Orders[MonthNumber] = MAX( Orders[MonthNumber] ) - 1
&& Orders[Day] <= MAX( Orders[Day] )
)
)
The Idea of this equation is to be able to display the previous months rolling total on a chart with the X axis as "DAY" (so 1-31) Then you can view the current month, previous month, same period last year all on the same chart or table.
Try something along these lines:
Rolling_Total_Previous_Month =
VAR CurrentMonth = MAX(SalesInvoice[Date])
VAR PreviousMonth = EOMONTH(CurrentMonth,-1)
RETURN CALCULATE(SUM(SalesInvoice[Sales]), SalesInvoice[Date] <= PreviousMonth)
To start of, I have a data like this in a table called as Orders-
Date Amount
12/12/2017 100
12/12/2017 200
12/12/2017 300
1/1/2018 400
1/1/2018 500
I first create a calculated column called as Year & Month by using the formula:-
Year = YEAR(Orders[Date])
Month = FORMAT(Orders[Date],"mmmm")
Then I create a column called as Month Number which will be helpful for sorting when more than one year is involved in the table and as well as to Identify the Previous Months.
MonthNumber = DATEDIFF(Min(Orders[Date]),Orders[Date],MONTH)
Current Month Sales can be a measure or a Calculated column. Qn the Question, you had your answer for current month sales via a calculated column and if you want to go for a measure then something like this would work on a summary table.
Current Month Sales = SUm(Orders[Amount])
I would also create a column called as Key:-
Key = Orders[MonthNumber] & Orders[Category]
Now, for the Previous Month Sales, I would create a measure that looks for selected MonthNumber that we created.
Previous Month Sales =
Var SelectedCategory = SELECTEDVALUE(Orders[Category])
Var SelectedMonthNumberr = SELECTEDVALUE(Orders[MonthNumber]) - 1
Var ReqKey = SelectedMonthNumberr & SelectedCategory
Return
IF(ISBLANK(SelectedCategory) <> True(),
CALCULATE(SUM(Orders[Amount]),FILTER(ALL(Orders), Orders[Key] = ReqKey)),
CALCULATE(SUM(Orders[Amount]),FILTER(ALL(Orders), Orders[MonthNumber] = SelectedMonthNumberr)))
or to your Measure
PREVIOUS_MONTH_ROLLING_TOTAL =
CALCULATE(
[Current Sales]
,FILTER(
ALL( Orders )
,Orders[MonthNumber] = MAX( Orders[MonthNumber] ) - 1
&& Orders[Day] <= MAX( Orders[Day] )
)
)
You can just add another filtering item as && Orders[Category] = SELECTEDVALUE(Orders[Category]) but won't work when you don't have any categories selected or on a table or visual which doesn't have categories. So, you would need to define an if else logic here as I have quoted on my measure formula.
Do let me know, if this helps or not.
I have daily sales data and I would like to create a measure or a column that calculates the monthly sales trend based on the average daily units sold in the month.
For example, as of 08/17/2017, we have had 12 working days this month and 360 units sold. This is an average of 30 units per day. So to calculate the trend manually, I would take 30 units/day and multiply it by the 23 total working days in the month for a trend of 690 units sold.
Here is some sample data.
EDIT: Adjusted the explanation and measure definitions based on the new info that was added to the post
You can create three measures to help you reaching your final result. In this example I'm merely splitting the measure into three parts to increase the readability. You can put it all together in a single measure if you like.
The first measure gives you the number of units sold. This is just a simple sum of units sold, since you have already added a month filter to your measures in your sample:
Sales:=SUM('SalesTable'[Items Sold])
The second measure gives you the number of working days for the filtered month up until the latest entry in your Sales Table:
WorkingDaysToDate:=
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[Date] > CALCULATE(MAX('SalesTable'[Date]))
&& [Type] = 'Work Day'
)
)
The third measure gives you the total number of working days for the filtered month:
WorkingDays:=
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
[Type] = 'Work Day'
)
)
In the end you can combine the three measures to get your month trend:
MonthTrend:=DIVIDE([Sales], [WorkingDaysToDate]) * [WorkingDays]
Total Month To Date Sales
TotalMTDSales = SUM('Sales Table'[Items Sold])
Total Month To Date Work Days
TotalMTDWorkDays = CALCULATE(
COUNT('DateTable'[Date]),
FILTER(ALLSELECTED('DateTable'), 'DateTable'[Date]<=MAX('SalesTable'[Date]) &&
'DateTable'[Type] = "Work Day"))
Total Work Days
TotalWorkDays = CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[Type]= "Work Day"))
Trend = ([TotalMTDSales] / [TotalMTDWorkDays] ) * [TotalWorkDays]
Filter by Month
I want to calculate annual revenue for each month from monthly revenue data. Sample data is shown as below:
e.g. For annual revenue of 2015 May = sum of monthly revenue from 2015 Jan to 2015 May, and so on.
The problem is, the Monthly Revenue is a measure. I want to create a measure for Annual Revenue as well, so that it can interact with other filters. However, I only know how to write the expression using Calculated Column:
Annual Revenue =
CALCULATE(
[Monthly Revenue],
FILTER(
'Month',
'Month'[Year] = EARLIER('Month'[Year]) &&
'Month'[MonthKey] <= EARLIER('Month'[MonthKey])
)
)
How can I translate the above expression so that it will work with Measure?
It sounds like what you want is a YTD measure for any given date (i.e. in May 2015, YTD is January-April 2015). I typically wouldn't do this using a [Monthly Revenue] measure and a Month table. I'd do this using a regular date table, a base Revenue measure, and DATESYTD.
However, using the MONTH table as you've outlined, this is what I'd do for a measure:
Annual Revenue Measure =
CALCULATE (
[Monthly Revenue],
FILTER (
ALL ( 'Month' ),
'Month'[Year] = MAX ( 'Month'[Year] )
&& 'Month'[MonthKey] <= MAX ( 'Month'[MonthKey] )
)
)
You'll note it's almost the same as you have for your calculated column, except using MAX rather than EARLIER (since EARLIER only applies to calculated columns).