I am trying to create a power BI calculation as an average per day of how many times a code was tripped. The dax calculcation that I have
Count Trips average per Day =
AVERAGEX(
KEEPFILTERS(VALUES('ruledata (2)'[Date].[Day])),
CALCULATE([Count Trips])
)
works fine when the average is being calculated over a couple days. I double checked this by hand and can confirm that it is accurate until at least 2 weeks. However once the time range increases to include months the average starts getting ridiculous and begins displaying average trips /day values that are much higher than the highest number of trips on a single day. I have confirmed that the data in the graph is correct
So I know that the values should reflect what is in the graph. In this two month example the DAX formula calculated the average to be 149.03 but the actual average/day should have been 82.8.
In general is there some sort of error in the DAX formula that I am using that could cause this?
I guess that 'ruledata (2)'[Date].[Day] is the day of the month. So if you take the average it will be wrong because when you take the average of e.g. March and April you will divide the total trips by 31, and not by 61 (30+31). So use 'ruledata (2)'[Date].[Date] instead.
Related
I am having a big problem, I have a table that has counts of employees the clocked in a a specific time rounded off to 15 minute increments each day. Included in the table are the end times. I am trying to create a bar graph which shows the 15 minutes time windows along the X axis and the Y axis should show the total number of people on the clock at that time however all I can get it to show is how many people "clocked in" at each of those spans. I'm not sure what I am doing wrong. I made a separate time table in 15 minute increments and related it to the employee table and still, same result. ANy help would be greatly appreciated!!!
I am using a simple measure to get the sum. SUMEMPCNT=SUM('data'{EMPCNT])
Here is a sample of the data table:
Here is a sample of the current chart.
You can use the build in Quick Measure "Runnung total" to get your DAX formula:
It will give you this measure:
Number running total in TimeStamp =
CALCULATE(
SUM('Table'[Number]),
FILTER(
ALLSELECTED('Table'[TimeStamp]),
ISONORAFTER('Table'[TimeStamp], MAX('Table'[TimeStamp]), DESC)
)
)
that you can visualize in a clustered column chart:
I have a promised hours calculation that looks at two dates (Coalesce) and gets the number of weeks in the month and then multiply it by the max promised hours for an employee which has a row for every week of the month. The employee could have 5 rows for every entry a week and the promised hours shows up the same as for example 40 for that week, thus why I have to take the max instead of do a sum. But at the end I need to show the total number of promised hours per week for whatever timeframe is chosen in the date slicer per employee.
Promised Hours Calc = CALCULATE(WEEKNUM(Max([CoalesceActualStart_AbsenceStart]),1)-WEEKNUM(MIN([CoalesceActualStart_AbsenceStart]),1))*MAX(FSLData[PromisedHours])
I then need it to do a sum for every employee on the above calculation.
I am getting all sorts of errors trying to do a sum on the calculation as a whole.
What you write is confusing and incomprehensible. That's why you get the errors. As soon as you are able to formulate your problem in such a way that others can understand it, you will understand it yourself and the errors will go away.
Is there a DATEADD equivalent for hours?
The smallest interval for DATEADD is DAY, but I need it to be HOUR.
I have a running total number that grows once per hour, I need to make a measure that calculates the hourly consumption. The total dataset spans over many years, with 24 readings per day, every day.
For example for monthly calculations (on a different solution) I use
Monthly = SUM('Readings'[VALUE]) - CALCULATE(SUM('Readings'[VALUE]), DATEADD('Date'[Date], -1, MONTH))
I need a similar solution to calculate hourly consumption for each of the 24 hours.
Sample table 'Readings':
View Table
So I would need a measure that knows for example on 01/01/20 at hour 1 (01:00) the consumption was 5 (145-140) etc.
I have monthly results that I need to present as a 3 month rolling average, sometimes at a monthly level and sometimes as a sum of the 3 month rollling average for the quarter/year.
At the monthly level I've found the below formula to work well:
3-Mo Rolling Avg = CALCULATE([Market Performance], DATESINPERIOD(Calendar_Lookup[date], MAX(Calendar_Lookup[date]), -3, MONTH))
/ CALCULATE(DISTINCTCOUNT(Calendar_Lookup[Year_Month]), DATESINPERIOD(Calendar_Lookup[date], LASTDATE(Calendar_Lookup[date]), -3, MONTH))
But, when I show quarterly or annual results it shows one 3 month average instead of a sum of the 3 month averages for the period. How would you solve this?
The options I can see are:
Create a column in either Power Query or DAX that holds the 3 month averages so then I can SUM them as needed? Any advice on how to do this?
Figure out how to do a SUM of a measure. Any advice on how to do this?
Build a series of measures at the monthly, quarterly and annual level. Not a great solution as it doesn’t allow me to work fast when performing analysis because I have to be careful of pulling the right measure.
Any advice would be appreciated! Thanks!
But, when I show quarterly or annual results it shows one 3 month average instead of a sum of the 3 month averages for the period. How would you solve this?
Based on this part, it sounds like you need one of the iterator functions. In this case it sounds like a SUMX
The basic layout would be something along the lines of
Measure:= SUMX( VALUES(Calendar_Lookup[Year_Month] ) , [3-Mo Rolling Avg] )
This measure would first using VALUES function generate a distinct list of each [Year_Month]. It would then calculate using your existing [3-Mo Rolling Avg] for each [Year_Month] and then sum the results.
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.