I have, in PowerBI (October 2017 release) some data showing the snapshotted output of some solar panels at five-minute intervals.
I presently have a measure which calculates the total production for each day by getting a sum of the instantaneous readings for the day and dividing by 12 (because there are 12 readings per hour) and then shows the average of this daily amount over whichever period is in the current context:
Avg Daily Production (KWh) =
AVERAGEX(SUMMARIZE('Solar Output', 'Solar Output'[Date], "Daily Production (KWh)", SUM('Solar Output'[Production (KW)]/12), [Daily Production (KWh)])
For my visualisations I'd like to show a chart which displays the average production at various times of the day compared to the production at that time for the best day, i.e. the day with the highest value for [Avg Daily Production (KWh)].
Here is my working so far:
Identify the top day by using
Best Day = TOPN(1, SUMMARIZE('Solar Output', 'Solar Output'[Date], "Daily Production (KWh)", [Avg Daily Production (KWh)]), [Daily Production (KWh)], DESC)
But this produces a row, not a scalar, and I can't quite work out how to just get this date and use it as a filter for a measure like this:
Production On Best Day (KW) =
CALCULATE(SUM([Production (KW)]), FILTER(ALL('Solar Output'[Date]), 'Solar Output'[Date] = [Best Day]))
The chart I want would look like this, with the average production for the selected dates in green and then another series showing the production at those times on the best day pencilled in red.
Can't really get my head around the calculations involved but I hope I get your requirement.
So you want to plot two lines on the same chart, one always being the data from the best day as reference, and the other one the data selected from the date filter, right?
You're actually pretty closed to the solution with the info given above.
I just modified your DAX to:
Production On Best Day (KW) =
CALCULATE(
SUM('Solar Output'[Average]),
FILTER(
ALL('Solar Output'[Date]),
'Solar Output'[Date] = VALUES('Best Day'[Date])
)
)
(Not quite sure how you compute your intermediate measures so you may need to adjust according to your measures)
Yes, TOPN() returns a table, so you can get the date value using VALUES('Best Day'[Date]) and use it for comparison.
Results:
Alternate approach to solve this issue is to use the MAXX() function to get a scalar value out of the the table returned by TOPN().
This works where MAX() doesn't because MAXX() accepts a table expression as its first argument (the table expression is the result of the TOPN() function) where MAX() only takes columns from existing tables.
Best Day = MAXX(TOPN(1,
SUMMARIZE(ALL('Solar Output'),
'Solar Output'[Date],
"Daily Production (KWh)",
[Avg Daily Production (KWh)]),
[Daily Production (KWh)],
DESC),
[Date])
The benefit of this approach is that it should work in versions of DAX with no calculated table support (e.g. SSAS 2014, Excel 2013).
Related
I have an interesting situation in which I need to develop running (moving) totals without Time Intelligence.
I do not have a special Date dimension table in my Power BI data model.
See the source table below:
I have a measure:
TotalLaptops = SUM(TableSource[Laptops])
I need to develop a running total, which is only partially date related. I have DeliveryDates that spread across years. I need to get the cumulative sum taking each of the 3 groups to account without worrying about how the dates spread across months, or even years. However, the order of the dates is important for the cumulative total (obviously).
I need a new measure called [LaptopRunningTotal].
Any idea on how to develop the new measure?
LaptopRunningTotal = CALCULATE (
[TotalLaptops],
FILTER (
ALL(TableSource),
TableSource[DeliveryDate] <= MAX(TableSource[DeliveryDate])
&&
TableSource[Group1] = MAX(TableSource[Group1])
&&
TableSource[Group2] = MAX(TableSource[Group2])
&&
TableSource[Group3] = MAX(TableSource[Group3])
)
)
Is this one above okay ? Am not sure whether the above is fool-proof, please let me know.
I'm using Power Bi desktop to create a sales dashboard, and ran into a small code issue.
I need to calculate average sales in a period of working days, and tried:
TOTALYTD([Sales];
dimCalendar[Date];
dimCalendar[WorkingDays]<=16)
16 is the related working day for 22APR2019 in Brazil.
After that I plan to divide it by a month count or another similar method.
The hard coded 16 works very well, however when I try to use another formula instead:
TOTALYTD([Sales];
dimCalendar[Date];
dimCalendar[WorkingDays]=CALCULATE(MAX(dimCalendar[WorkingDays]);
LASTDATE(dimCalendar[Date])
))
It gives an error that I can't use calculate in a true/false expression.
I tried to use calculated column, but doesn't work as well.
Do you have any idea of how I can create this measure?
I've been doing a lot of research on this question over the past few days, but none of the articles I've researched have been able to do. I'm trying to find the difference between two dates in Power BI that excludes weekends, but it also needs to calculate the differences in times as well. All of the articles I've seen have been able to find the difference in the dates themselves, but for my specific problem, the times are important.
For example,
I'm trying to find the difference between Pickup Date/Time and Created Date/Time. The data I am looking at is to find all the shipments that were entered into the system two business days in advance of the pickup date, and those shipments need to be entered in before noon that day.
I've created a Date table that has all dates between 2018-2020 that show whether it's a weekend or a weekday, but I haven't been able to figure out how to basically do Pickup From - Created From and filter out the weekends.
Any help with this would be greatly appreciated.
My data is below that i'm trying to use.
Supplier Lead Times Table with Created/Date Time and Pickup From/Date Time
Lead Time Days
The Lead Time days currently is just ('Supplier Lead Times' [Pickup From Date/Time] - 'Supplier Lead Times'[Created Date/Time]).
Even if I could use the DATEDIFF HOURS function for this, that would work, i'm just having trouble filtering out the weekend days. I have a calendar table that has all the weekdays/weekends
Calendar Week Table
As far as I checked, your "Create Date" and "Pickup Date" fields are always weekdays. Therefore, if we calculate the total difference than put 24 hour back for each weekend, that would work. Try to create a quick measure column like below and apply it to your table:
Difference =
var weekends =
SUMX(
SELECTCOLUMNS(
CALENDAR(min('MyTable'[CreatedDate]), min('MyTable'[PickUpDate])),
"Date", min('MyTable'[CreatedDate]),
"BDay", IF(WEEKDAY([Date],3) >= 5, 1, 0)
),
[BDay]
)
return DATEDIFF(min('MyTable'[CreatedDate]), min('MyTable'[PickUpDate]), HOUR) - weekends*24
Maybe this is an easy one but since I’m very new in DAX and PowerBI I can’t figure it out. My database has daily data ranging from MAY/17 to JUN/17 (and it’ll still going in the future). It has information of DATE, DAY, YRMTH (year-month), QT_APRV (approved customers) and QT_TOTAL (total consumers). Sample below (using Excel just to be quicker):
I wanted to create in PowerBI a bar chart with QT_TOTAL per day and a line chart with approved rate of consumer. For the rate, I used:
APPRV_RT = SUM(database[QT_APRV]/SUM(database[QT_TOTAL])
And then, selecting only a month by time in the chart (just like I want), I have:
Perfect, but now I want to create a new line chart, showing the approved rate in each respective day of the last month. Using my example, when june data are select, the first line chart has to show the daily approved rate of june AND the other the approved rate of may, in order to make it comparable (june1 -> may1; june12 -> may12 and so on). Here’s what I want:
How to make this automatically, in order to make each month comparable with the previous? I thought about some DAX formula involving a sum with filtering current month minus 1, I don’t know how to do it.
Any ideas?
UPDATE (07/08/2017)
I tried what Rasmus Dybkjær suggested me, and I thing I'm in the right path.
APPROVED_RATE_PREVIOUS_MONTH = CALCULATE([APPROVED_RATE_CURRENT_MONTH];PARALLELPERIOD(dCalendario[DataBase];-1;MONTH))
However, it returned the approved rate from the previous month as a whole (67,0% in May), not each day as I wanted:
Any suggestions?
You should be able to use the DAX function called PARALLELPERIOD() for this purpose. The PARALLELPERIOD() function takes a date column and shifts it a number of periods back or forward.
For example, you could use it like this to calculate your approved rate shifted one month back:
ApprovedRateLM =
CALCULATE(
DIVIDE(
SUM(database[QT_APRV]),
SUM(database[QT_TOTAL])
),
PARALLELPERIOD(database[Date],-1,month)
)
Note that it is important that your [Date] column contains a date type. Otherwise the PARALLELPERIOD function will not work.
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.