Project revenue calculation in DAX - powerbi

I need to calculate the ongoing revenue for installation + maintenance for projects and calculate the monthly revenue for controlling purposes in DAX in Power BI.
The problem is the following.
The projects are stored in a table CONTRACTS like this:
And I have a separate date table INST_DATE_TABLE:
The tables are connected via the [INSTALLATION_DATE] field.
For every month the revenue is the total of the [INSTALLATION_REVENUE] if the installation was carried out that month plus from the first month on the monthly maintenance revenue which is given as the [MAINTENANCE_COST_PER_UNIT] * [MAINTENANCE_UNIT] / 12.
And the maintenance revenue should be only calculated if the current date is beyond the installation date!
Some contracts are not yet signed, so they dont't have an installation date set (NULL)
So the INSTALLATION REVENUE DAX is like this:
.INSTALLATION_REVENUE =
CALCULATE (
SUMX(CONTRACTS;
CONTRACTS[INSTALLATION_REVENUE]
);
CONTRACTS[INSTALLATION_DATE] > 0
)
And the MONTHLY REGULAR REVENUE is like this:
.REGULAR_REVENUE =
CALCULATE (
SUMX(CONTRACTS;
CONTRACTS[MAINTENANCE_COST_PER_UNIT]*CONTRACTS[MAINTENANCE_UNIT]
) / 12;
CONTRACTS[INSTALLATION_DATE] > 0
)
For all dates I can calculate the cash flow of the latter like this:
.REGULAR_REVENUE_ONGOING =
CALCULATE (
[.REGULAR_REVENUE];
ALL(INST_DATE_TABLE[INSTALLATION_DATE])
)
which gives me a nice series of monthly revenues for all periods. But I only would like to see this for the periods that are beyond the installation date!
So lets say filtered on contract 1 I have now the following cash flow:
But for periods before 2019.04.01 I would like to see zeros!
How can I do that?
I just can't filter on dates referring to the installation date of the project!
After I have the expected result for one contract it would be easy to sum it up for all contracts like this
.TOTAL_REVENUE =
[.INSTALLATION_REVENUE] + [.REGULAR_REVENUE_EXPECTED]
UPDATE:
I created a cumulative total to display the ongoing revenue as such:
.REGULAR_REVENUE_ONGOING =
CALCULATE (
[.REGULAR_REVENUE];
FILTER(
ALL(INST_DATE_TABLE[INSTALLATION_DATE]);
INST_DATE_TABLE[INSTALLATION_DATE
<=MAX(INST_DATE_TABLE[INSTALLATION_DATE])
)
)
this displays the correct series, but now I have another problem. When I try to cumulate this already cumulative data series it does not add up as a cumulative data series!
Any help would be appreciated
.REVENUE_TOTAL_CUMULATIVE =
CALCULATE(
[.REVENUE_TOTAL];
FILTER(
INST_DATE_TABLE;
INST_DATE_TABLE[INSTALLATION_DATE] <= MAX(INST_DATE_TABLE[INSTALLATION_DATE])
)
)

Assuming there are no end dates to your ongoing revenue, then try:
.REGULAR_REVENUE_ONGOING =
VAR DateMin =
CALCULATE(
MIN ( CONTRACTS[INSTALLATION_DATE] ),
ALL ( INST_DATE_TABLE )
)
VAR DateMax =
MAX ( INST_DATE_TABLE[INSTALLATION_DATE] )
RETURN
SUMX (
FILTER (
ALL ( INST_DATE_TABLE ),
INST_DATE_TABLE[INSTALLATION_DATE] >= DateMin && INST_DATE_TABLE[INSTALLATION_DATE] <= DateMax
),
[.REGULAR_REVENUE]
)
And for a cumulative total revenue:
.REVENUE_TOTAL_CUMULATIVE =
VAR DateCurrent = MAX ( INST_DATE_TABLE[INSTALLATION_DATE] )
VAR CumulativeInstallationRevenue =
CALCULATE (
[.INSTALLATION_REVENUE],
FILTER (
ALL ( INST_DATE_TABLE ),
INST_DATE_TABLE[INSTALLATION_DATE] <= DateCurrent
)
)
VAR CumulativeOngoingRevenue =
SUMX (
FILTER (
ALL ( INST_DATE_TABLE ),
INST_DATE_TABLE[INSTALLATION_DATE] <= DateCurrent
),
[.REGULAR_REVENUE_ONGOING]
)
RETURN
CumulativeInstallationRevenue + CumulativeOngoingRevenue
See https://pwrbi.com/so_55808659/ for worked example PBIX file

Related

SUMMARIZE or SUM values based on Date fields in another table

I am trying to do a burndown graph on PowerBI.
My data is a list of tasks. Each task has a numerical value (EFFORT) assigned to it and there is a total amount of effort for any given month (sum of all EFFORT). As tasks as set to DONE, the ongoing effort should be deducted from a running total and that value used to plot a graph. I have 3 columns
I would like to have measure to calculate EFFORT REMAINING for each date, i.e.
EFFORT REMAINING = TOTAL EFFORT - (EFFORT WHEN TASKS ARE DONE FOR EACH DAY)
For example,
I did get the consecutive dates displaying:
Burndown = CALENDAR(DATE(2022,7,1),DATE(2022,7,31))
and also the total effort (starting value)
TOTAL EFFORT = SUM(Issues[EFFORT])
Now for each date in table, I need to minus the accumulating total of EFFORT when the status is set to DONE
EFFORT REMAINING = Burndown[TOTAL EFFORT]-SUM(Issues[EFFORT]="DONE" ....
Im stuck after this last point. Can anyone help, please?
you are so close to the answer ). Convert SUM(Issues[EFFORT]="DONE" to:
CALCULATE(
SUM(Issues[EFFORT])
, SUM(Issues[Status]="DONE"
)
Have a nice day.
Please try this measure:
Please ensure that (1-Many) relationship is created between Burndown [Date] and Issues[ISSUE_CREATED] columns.
EFFORT REMAINING =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( Issues, Burndown[Date] ),
"Total Effort", CALCULATE ( SUM ( Issues[EFFORT] ) ),
"Tasks Completed", CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" ),
"Effort Remaining",
CALCULATE ( SUM ( Issues[EFFORT] ) )
- CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" )
)
VAR Result =
SUMX ( TblSummary, [Effort Remaining] )
RETURN
Result
After that, you can create a clustered column chart, and put [Date field] on calendar table on X_axis and put 'EFFORT REMAINING' measure on Y_axis(Value axis) to see the result.
I hope It solves your problem.
Bonus Info:
If you want to see your Summary table, create a "New Table" and paste this code:
Summary_Table =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( Issues, Burndown[Date] ),
"Total Effort", CALCULATE ( SUM ( Issues[EFFORT] ) ),
"Tasks Completed", CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" ),
"Effort Remaining",
CALCULATE ( SUM ( Issues[EFFORT] ) )
- CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" )
)
VAR Result =
SUMX ( TblSummary, [Effort Remaining] )
RETURN
TblSummary
The result It produces:
Note: I have limited access to your data sets as you shared above. The result will be exact with your full dataset.

Rolling Year: Actual And Last Year

I have the following fields:
Year
Category
Maker
Month
Month Number
Sales Volume
Sales
Date
So, I have in my dash a filter for "Month Number" and "Year":
My goal is to create two new measure; first with the Rolling Year that need to sum 12 months, ending in the moment that the user select in the mencioned filters. For example if y select Year 2021 and Month 01. The Rolling Year need to sum the sales of a selected category since 2020-02 to 2021-01 (thats mean always 12 months since a pivot month).
For thesecond is exactly the same, a measure called Rolling Last Year, it need to be a rolling sum too, but for the last period in order to compare. Taking the same example if I have the period 2020-02 to 2021-01. The Rolling Last Year for the last period should be 2019-02 to 2020-01.
I tried with this DAX code, that extracted from Microsoft page but without success:
Rolling Year =
CALCULATE (
SUMX ( Table, Table[Sales] ),
FILTER (
ALL (Table[Date] ),
AND (
Table[Date] <= MAX ( Table[Date] ),
DATEADD ( Table[Date], 12, MONTH ) > MAX ( Table[Date] ))))
I share you an extract of my base:
Thanks in advance !!!
Based on the table and code you have shared, it is unclear from where the date filters are being applied. In case you have not done it, I strongly suggest to delete the [Month] and [Month Number] field from your Sales table and keep them in a separate Calendar table, from where the filters should be selected. Then, a simple tweak on you current formula should do the trick:
Rolling Year =
CALCULATE (
SUMX ( Table, Table[Sales] ),
FILTER (
ALL ('Calendar'[Date] ),
AND (
Table[Date] <= MAX ( 'Calendar'[Date] ),
DATEADD ( 'Calendar'[Date], 12, MONTH ) > MAX ( 'Calendar'[Date] ))))
However you can try with this variation for the code, a little bit optimized so as not to scan your whole Sales table each time:
Rolling Year =
VAR EndSelectedDate = MAX ( 'Calendar'[Date] )
VAR StartSelectedDate =
CALCULATE (
MAX ( 'Calendar'[Date] ),
ALL ( 'Calendar'[Year] ),
'Calendar'[Year]
= MAX ( 'Calendar'[Year] ) - 1
)
RETURN
CALCULATE (
SUM ( Table[Sales] ),
ALL ( 'Calendar' ),
'Calendar'[Date] <= EndSelectedDate,
'Calendar'[Date] > StartSelectedDate
)

calculatation day over day

Hi I need to calculate day over day
I attached the pbix file https://1drv.ms/u/s!Amd7BXzYs7AVhBBCo_Ls7q5IkrXH?e=d1nNmA 
I've tried the following calculated measure but actually it returns wrong values, it returns sales for current date, but I need to return sales for previous day. How to correct it?
sales day over day = var _maxdate=CALCULATE(max('Date'[Date]), ALLSELECTED('Date'[Date]))
var _mindate=CALCULATE(min('Date'[Date]), ALLSELECTED('Date'[Date]))
var dates=filter(values('Date'[Date]), 'Date'[Date]<=_maxdate && 'Date'[Date]>=_mindate)
return if(ISEMPTY('Date'), BLANK()
, calculate(sum(Sales[Sales]), FILTER(Sales, Sales[Date]<=_maxdate && Sales[Date] >=_mindate && PREVIOUSDAY('Date'[Date])))+0
)
It seems that your measure works. I've got sales for previous days.
You may need to use simple measures as follows:
TotalSales =
SUM ( Sales[Sales] )
PreviousDaySales =
CALCULATE ( [TotalSales], PREVIOUSDAY ( 'Date'[Date] ) )
DayOverDayChange =
DIVIDE ( [TotalSales], [PreviousDaySales], 0 )
The result (not on your data):

SELECTED Value from slicer in not filtering previous month results

I have a dataset like below and I joined it with a calendar table on a created date.
I am trying to do an avg daily cases MoM analysis, I am comparing the current month vs. the Previous month's avg daily cases.
For example, IF I got 60 distinct cases in May, and my daily avg cases for May is 2 cases per day. I want to calculate the same for the previous month when I select Month from the filter.
Here I selected May-2021. I want my measure to calculate Apr-2021 Avg Daily cases.
So I created two measures, one is for the selected month, and another one is for prior avg daily cases.
Avg Daily Cases =
VAR Selected_Month =
SELECTEDVALUE ( 'Date'[MMM-YYYY] )
VAR Month_Days =
CALCULATETABLE (
VALUES ( 'Date'[DateAsInteger] ),
FILTER ( 'Date', 'Date'[MMM-YYYY] = Selected_Month )
)
RETURN
CALCULATE (
AVERAGEX ( Month_Days, CALCULATE ( DISTINCTCOUNT ( MyTable[CaseNo] ) ) )
)
Prior Month Avg Daily Cases
Avg Daily Cases Prev Month =
VAR Selected_Month =
SELECTEDVALUE ( 'Date'[MMM-YYYY] )
VAR Last_Month_Days =
CALCULATETABLE (
VALUES ( 'Date'[DateAsInteger] ),
FILTER (
'Date',
MONTH ( 'Date'[Date] )
= MONTH ( Selected_Month ) - 1
&& 'Date'[Year] = YEAR ( Selected_Month )
)
)
RETURN
CALCULATE (
AVERAGEX ( Last_Month_Days, CALCULATE ( DISTINCTCOUNT ( MyTable[CaseNo] ) ) )
)
Avg Daily Cases measure working fine and getting the expected results, however, Avg Daily Cases Prev Month is not working.
Suppose you have total case of 30 in May and 60 in June, and you have the following dataset in order to return comparison for two using single selection and accept the answer if helping :)
First I have create the following table for selection
Current period average case
Current daily case =
var caseTotal = CALCULATE(DISTINCTCOUNT(Sheet1[Case]),
FILTER(Sheet1,Sheet1[Period] in {SELECTEDVALUE(Selection[Selection])}))
return
caseTotal / DAY(EOMONTH(SELECTEDVALUE(Selection[Selection]),0))
Prior comparison
Prior daily case =
var caseTotal = CALCULATE(DISTINCTCOUNT(Sheet1[Case]),
FILTER(Sheet1,Sheet1[Period] in {FORMAT(EDATE(SELECTEDVALUE(Selection[Selection]),-1),"mmm-yyyy")}))
return
caseTotal / DAY(EOMONTH(EDATE(SELECTEDVALUE(Selection[Selection]),-1),0))
Result:

I will like a script in power bi that will calculate percentage increase or decrease from one month to the previous month

I want to display percentage increase or decrease in total for each month as I select each month i.e when I click on FEB, it should tell me whether there was a percentage increase/decrease in expenses compared to JAN.
I have tried different codes but keep getting an error message.
Here is a DAX CODE I tried:
change perc =
VAR ValueLastMONTH =
CALCULATE (
SUM ( population[TOTAL] ),
FILTER (
population,
population[MONTH]
= ( EARLIER ( population[MONTH] ) - 1 )
&& population[CATEGORY] = EARLIER ( population[CATEGORY] )
)
)
RETURN
IF (
ISBLANK ( ValueLastMONTH ),
0,
( population[TOTAL] - ValueLastMONTH )
/ ValueLastMONTH
I want a new column created to display the percentage increase or decrease from a month to its previous month.
Here is a screenshot of the excel document:
The Column 'Month' is not of type date. How would PowerBi know the text APR represents April? You need to make this column a date.
Now you need to change the script to work with DateDiff:
change perc =
VAR ValueLastMONTH =
CALCULATE (
SUM ( population[TOTAL] ),
FILTER (
population,
DATEDIFF(population[MONTH], EARLIER ( population[MONTH] ),MONTH) = 1
&& population[CATEGORY] = EARLIER ( population[CATEGORY] )
)
)
RETURN
IF (
ISBLANK ( ValueLastMONTH );
0;
( population[TOTAL] - ValueLastMONTH )
/ ValueLastMONTH)