I have issues with Data sorting
I have spend data by period which is a combination of year and month. For example if the period is March 2019 then period would show 201903. Data type of this period field is "Number". I have spend data starting from period 201501 to 201903.
Now I am creating a line chart to show spend trend with period in X axis and spend in Y axis. I have sorted (ascending) the chart by period, however sorting works ok partially, means period that I see in the chart are mentioned below:-
201708,201801,201806,201807,201808,201809,201810,201811,201812,201901,201902,201903
Not sure why sorting option is not working
Also in the Visual Level filter I want to show trailing 12 months spend, details of Visual Level filters that i selected are as follows:-
Visual Level Filter - Period
Filter Type - Top N
Show item - Bottom 12
By Value - Spend Amount
The expected result that I want in the line chart is :-
201804,201805,201806,201807,201808,201809,201810,201811,201812,201901,201902,201903
I checked the data and confirm it has all periods starting from 201501 to 201903
Any help would be highly appreciated
Related
I would need a report that shows variances for the current period, next period, half-year and year-end.
There is a period filter from 1 to 12 representing the periods in a year.
I can build up a table that shows the difference:
for the current period (can be amended based on the period filter)
for full-year (using ALL function to ignore the period filter)
But I don't know how to write a dax that filter just for the first 6 periods as half-year.
Or add one to the current period filter to shows the next period-related variance.
Also, that should be dynamic. This means if I adjust the period filter it should show always be the next period. (If the filter is set for 1 to 4 it returns 1 to 5; set 2 to 7 returns 2 to 8).
Could you please help me with how to do that?
Thanks
So, let's say we have 2 databases.
The plan for the current year and the actuals:
Excel
And I would like to see the difference between them in one visualization.
If the period set is 1 to 2:
for the current period shows: sum plan (1-2) - sum Actual (1-2)
next period: sum plan (1-3) - sum Actual (1-3)
Half Year: sum plan (H1) - sum Actual (H1)
FY: sum plan (1-12) - sum Actual (1-12)
I am not able to understand exact query but it seems that as per your given examples it's more related to time intelligence formulas in PowerBi to given results based on specific time frames. (YTD, QTD etc)
Below is the link to address your query via time intelligence formula
https://www.analyticsvidhya.com/blog/2020/08/time-intelligence-power-bi/
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 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.
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
So I have made a spreedsheet to help me keep track of my power and gas bill - well the total cost of the bill anyway. This way as the months go on I am able to see what the average Power and Gas bill have been.
I am using only sheet1 and prefer to do it this way, so when I show my partner they don't need to flick through pages of numbers. It's right in front of them with Power & Gas in the next row - take a look at the image below.
So as you can see from the above (not including the J3 row) I have everything laid out in the layout I would like. This way when I get a bill emailed to me I add it, and then I can pay X amount and record that.
I know how to do =sum() and =average() but how can I limit it to only the power rows automatically.
The query should be looking up G column for power or gas and then whichever one it is get the H column next to it and then work out the cost per month by looking at the date the bill came out.
Power bill is every month so that easy, gas is every 3 months.
I know in open office they have the =if() command and I made it return TRUE when it was power but it does not seem that i can use just that function? I am wondering if maybe a TUT or example that outlines how we get the result like this.
Another example would be replace gas and power with tech toys i.e batteries over a year what was the real cost per monthly.
Ok after thinking outside the square - the answer I am using is this.
=AVERAGEIF(G3:G100;"POWER";H3:H100)/COUNTIF(G3:G100;"POWER")
I divided power by it's count as we get it every month
=AVERAGEIF(G3:G100;"GAS";H3:H100)/COUNTIF(G3:G100;"GAS")/3
I divided gas by 3 as we get it every 3rd month