Run into a problem.
I need to have a yearly reset on an entitlement value but the reset point is a different date for each person. A person gets entitlement 6 months after their start date, so that +6months date is when they should have a reset. Here is the +6months column i made:
+6m = DATE(YEAR('Employee List'[Emp. Dates]),
MONTH('Employee List'[Emp. Dates])+6,
DAY('Employee List'[Emp. Dates]))
I ran into this problem when i saw that the excess was taking away a persons entitlement by the amount of days took throughout their entire time at the company. Here is the measure for Excess:
Excess Days = CALCULATE(SUM('Employee List'[Entitlement]) -
SUM('Leave combined'[Duration1]))
This is taking away all recorded days even from a few years ago.
Can i make a measure that pretty much says if we are past the +6months date (DD/MM(Year doesnt matter i just need the same time every year)), then it will take away their entitlement from that +6months date and will not pick up any days from before the +6months reset?
e.g. if the +6months is March 1 2015, currently it is taking all the days took from their start to today, i want it to reset at every year on March 1 so it would only take data from March 1 2019 - today and will reset once we past March 1 2020. If a person has took 25 days a year on average and they only have 20 days entitlement, it should show they 5 excess days but for me now it is taking the total days took away from their entitlement.
I understand this is hard to explain and you may not get it but i am happy enough to explain.
Dummy Sheet
It is easier to create a calculated column to do this. Perhaps something like:
Calc =
VAR Person = TableA[Person]
VAR Date1 = EDATE(Entitlement[Start Date],6)
RETURN IF(TableA[Start]<Date1,0,TableA[Duration])
This column will make the duration 0, wherever the start date is lesser than the +6m date from entitlement. Once this column is created you can simply sum up the field at whatever level required, to get the desired output. Hope this helps.
Related
I'm currently working on inventory reconciliation, and I've struggling to fill all days of the calendar with the cumulative sum of product we're currently storing:
Inventory level ($). = CALCULATE(SUM(ledger[cost]),FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(ledger[Document Date])))
As you guys might notice it has at least 90% of all dates filled, however if we look closely to the graph, we can appreaciate March 5th of 2016 is missing just due to the fact there was no transaction during that day resulting on a blank value. However I'm trying to accomplish retrieving the previous day balance for those days with no transactions. e.g: for March 5th should have $17,038,462.32 (balance for the previous day March 4th).
I'm trying to work on another clause into the measure with functions such as EARLIER or LASTDATE, however I haven't been succesful.
Any insight or solutions works well thank you. Have a nice day.
You are using a wrong date field in your measure. Change it to the field from the Date table:
Inventory level. =
CALCULATE(
SUM(ledger[cost]),
FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(DimDate[Date])))
I'm trying to figure out how to spread the estimated hours for a project over the length of that project with a known end date.
Example, I have Project 001, it is 600 hours, and it is a six-month project that is due to release June 2020. Each of these values (project identifier, hours, length, and release date) are separate columns in a database.
In this example, Project 001 would add 100 hours to each month from January to June. If Project 002 had 300 hours with the same length and release date, now each month would have 150 hours.
The end goal is to get a forecast of how many hours we expect in each month for all the projects we have to determine the overall capacity demands for the month. So we'd have something like a bar chart that shows the total hours demand for each month based on the projects that will impact that month. Or we'd have a bar chart that shows the remaining capacity (fixed monthly capacity minus monthly estimated hours).
I haven't been able to determine how to generate something that will divide the hours backward over the length of the project based on the project end date. I'm still pretty new to Power BI, so I could do with some guidance on this one. I'm well versed in Excel and VBA, I understand the basics of creating measures and some of the ways Power BI "formulas" are written. Any help is much appreciated.
I made a small test table:
I added the column: HoursPerDay
HoursPerDay = Hours[Hours]/ DATEDIFF(Hours[StartDate];Hours[EndDate];DAY)
Next I made a calendar table:
Calendar = CALENDAR(MIN(Hours[StartDate]);MAX(Hours[EndDate]))
I added the measure HoursPerProject to this table:
HoursPerProject = CALCULATE(SUM(Hours[HoursPerDay]);FILTER(Hours;Hours[StartDate] <= VALUES('Calendar'[Date]) && Hours[EndDate] >= VALUES('Calendar'[Date])))
This is the important bit because it checks if it should include the hours for a prject on that day.
When putting this in a stacked column graph, you need to place the HoursPerProject in the value and the Date of calendar on the Axis. Hope this helps you.
I work in an educational department where the start date of our academic calendar changes every year. Some years it might be week 9 of the year, some years it might be week 10. There is no formula used to figure out this start date, it's based a combination of factors and is picked by humans.
I want to be able to compare calls received in week 1 of the academic calendar 2017 to calls received in week 1 of the academic calendar 2018 and 2019.
I am using PowerBI desktop and trying to create a calendar table that includes a column "academic calendar week" or similar.
Does anyone have any suggestions on how to offset start date of the calendar by a different number of weeks for each year?
In Power Bi my average matters per day is not stopping on the current day.
Avg Per Day = DIVIDE([Matters],SUM(Dates[IsWorkday]))
where IsWorkday = IF(ISBLANK(Dates[Holiday]),IF(Dates[DayOfWeekNumber]>1&&Dates[DayOfWeekNumber]<7,1,0),0)
and Matters = COUNT(BillingData[Item])
So today is the 27th of the month so 18 of 20 work days are completed for the
month. So need [matters]/18, not [matters]/20.
How do I factor that in to my average and not affect previous months.
Any help appreciated.
Sounds like you need to just add one more condition to your if statement to add in that the date is less than todays date. Check out this post. I think it might have the solution to your problem or at least give you the idea you need to solve the issue.
https://community.powerbi.com/t5/Desktop/Networkdays-DAX-function/td-p/38044
Need help in Data Analytics Calculations.
Currently, I am getting historical data for consumption as follows:
on above data, I am adding custom columns for calculating exact consumption(gallons) in no. of days. like:
Now, I have to plot month wise bar chart for consumption of respective Meter ID in 2016 year. But problem here is, I will have to calculate Every months consumption by dividing it in days in each respective month of 2016, and then only I will able to plot them monthly like:
y axis = consumption in every month
x axis = Jan Feb March Apr May Jun Jul Aug Sep Oct Nov Dec
so, in jan month, consumption should be = 10 + 100 + ((115/38) * 7) gallons
Notes: here, in ((115/38) * 7) : we are calculating avg consumption of single day 7 days in Jan and whole march and then getting last 7 day consumption of Jan so that we can add it in calculation of total consumption of Jan month
but how to add measure/custom column/new table for these calcualtions?
Thanks
What you need to do is relatively complicated, but the summary of my solution is:
Calculate the per-day consumption
Calculate the start and end date of each reading (e.g. the previous reading date plus one day, and the reading date)
Expand your data to have 1 row per day rather than 1-row per reading
You want to do these steps before you load the data into your data model (i.e. in your source system, or as the data is loaded using the Query Editor/Power Query).
Below, I assume you're using the Query Editor/Power Query. However, if you can use your source system, it's often the better choice (since the source system may be a database that is vastly faster than your desktop).
Note that your No. of Days calculation doesn't make sense to me. There are more than 38 days between 24 Jan 2016 and 31 Mar 2016. There are also more than 13 days between 10 Jan and 24 Jan. For this reason, it was difficult to tell whether you wanted a new reading to count on the day the previous reading was taken, or on the next full day. I assume the former. Also note, I've proceeded on the basis that your No. of Days calculation is correct
Calculate the Per Day Consumption
This is the easiest step, given that you have already calculated the Consumption and the No. of Days. Just divide one by the other. In the Query Editor, you can click in the Consumption (gallons) column and select Add Column > Standard > Divide. Under Value, choose Use values in a column and then select the No. of Days column.
Calculate the Start & End Date of Each Reading
The date of the reading is the end date, so you can rename Date to be End Date (since a reading is applied retroactively).
For the start date, in the Query Editor, you will need to add an index column (Add Column > Index Column). You will want to make sure your data is sorted by Meter ID and Date Ascending before doing this. Call the column Index.
Next, Add Column > Custom Column and pull the reading date from the prior row. Call the new column Previous End Date for now.
// A try is necessary because we can't get the previous row if there is no previous row (we'll get an error, which we can handle in the 'otherwise' block)
try
if
// See if the previous row is for the same Meter ID
[Meter ID] = #"Reordered Columns"{[Index] - 1}[Meter ID]
then
// If it is, grab the Reading Date from the previous row
#"Reordered Columns"{[Index]-1}[End Date]
else
// If this is the first reading for a meter, calculate the Start Date by subtracting the No. of Days from the End Date
Date.AddDays([End Date], -[No. of Days])
otherwise
// If this is the first row in the table, also calculate the Start Date by subtracting the No. of Days from the End Date
Date.AddDays([End Date], -[No. of Days])
Next, you'll want to add 1 to the Start Date, as we want the reading to apply to the day after the previous reading, not on the day of the previous reading.
Note, if you want the reading date to count in the prior period, subtract 1 from the End Date rather than add 1 to the start date (previous end date).
Expand your data to have 1 row per day
At this point, you should have a Meter ID, Start Date, End Date, and per day consumption column that reflects what you expect (i.e. the per day consumption is correct for the date range).
The final step is to duplicate each row for each date in the date range. There are several solutions to this outlined in this thread (https://community.powerbi.com/t5/Desktop/Convert-date-ranges-into-list-of-dates/td-p/129418), but personally, I recommend the technique (and video) posted by MarcelBeug (https://youtu.be/QSXzhb-EwHM).
You should end up with something more like this (after some removing & renaming of columns):
Finally
Now that you have one row per meter & date, with a per day consumption already calculated, you can build a visual. For example, you could do a column chart with Date on the Axis, and Consumption per Day as the value. By default, Power BI will recognize that Date is a date, and will roll it up by Year-Quarter-Month-Day. Press the little 'x' by Year and Quarter, and you'll have a chart that sums up the per day consumption by month. You can also drill down to individual date.
Further Reading
Reading a value from a previous row in Power Query
If Statements in Power Query
The AddDays function in Power Query
Adding Comments in Power Query
Catching Errors in Power Query
Converting a date range into a list of dates (Marcel Beug's solution)
A similar problem I previously answered