I have a table like in the attached image:
As you can see, I have power consumptions of houses by hour.
What I would like to do is create a measure to calculate the average of power consumption by day and other measure to sum this average of power consumption by days depending on a time interval introduced in a filter.
I know it could be easy by don't know how to start with this.
Thanks for your help!
Regards
Start by adding Calculated columns for Date and Time only:
Date = DATEVALUE(FORMAT('Table'[Datetime], "YYYY-MM-DD"))
Time = TIMEVALUE(FORMAT('Table'[Datetime], "hh:mm"))
With this you create a new Calculated table for consumption per day
Consumption per day =
SUMMARIZE(
'Table',
'Table'[Date],
"Avg. Consumption", AVERAGE('Table'[Consumption])
)
and consumption per day for a given time interval
Consumption per day and time interval =
CALCULATETABLE(
SUMMARIZE(
'Table',
'Table'[Date],
"Avg. Consumption", AVERAGE('Table'[Consumption])
),
'Table'[Time] >= TIMEVALUE("00:00"),
'Table'[Time] <= TIMEVALUE("01:00")
)
Related
I'm trying to find a 30-day rolling average of a measure [STORY COMPLETED]
The measure is calculated as:
STORY COMPLETED = CALCULATE(COUNT(SprintReportIssues[SPRINT_REPORT_STATUS]), SprintReportIssues[SPRINT_REPORT_STATUS] = "COMPLETED")
SPRINT_REPORT_STATUS can be one of four values: "COMPLETED", "COMPLETED OUTSIDE", "INCOMPLETED" or "REMOVED"
If you look at the image, I want something like:
Rolling Average Throughput of top row to be 19+18+13/3
Rolling Average Throughput of second row to be 18+13+14/3
Rolling Average Throughput of second row to be 13+14+9/3 and so on
enter image description here
Note: all data is on the SprintReportIssues table
I expect a DAX measure for Power BI, and I've tried using AVERAGEX, but I don't seem to be getting it right
This measure will solve your problem:
Rolling Average Throughput =
VAR __LAST_DATE =
LASTDATE('Table'[START DATE])
RETURN
AVERAGEX(
DATESBETWEEN(
'Table'[START DATE],
DATEADD(__LAST_DATE, -28, DAY),
__LAST_DATE
),
[STORY COMPLETED]
)
I have calculated measures for total Hrs and quantity with that I calculated (Hrs/Qty), and now I need to calculate running total of that.
Expected result: 6.18,7.52 and so on. But it's giving incorrect result. What's is the correct Dax formula? Can we calculate rolling total for calculated measure?
Power BI has a Quick Measure Running Total that is provided for exactly this purpose. And of course, you can also use Measures as Base Value for the calculation.
Please try this measures to achieve your goal:
% Of HR = SUMX(YourTable,DIVIDE([HR],[Qty]))
Rolling Total = CALCULATE(
[% Of HR],
FILTER(
ALL(YourTable[Week End Date]),
YourTable[Week End Date] <= MAX(YourTable[Week End Date])
)
)
If we test our measure on a visual:
i have a problem regarding my calculation. I want to visualize the running total over time (for example 01.07 after hours rounded to the nearest half hour to reduce computing power). I have 90 days of data in my dataset. The Problem i have is that the calculation for the dates long time ago (for example 01.12.2021) are super fast and the calculation for recent dates (05.07.2022) are super slow. I think that the measure calculates the running total for the whole column and then the date filter will be applied, which caused the extreme long calculation time for recent dates. Every day has the same amount of rows. Any idea how i can tell the measure to calculate the running total only for the selected date/date which i picked in my filter?
I used the following measures:
Average Sales =
'Measure Table X'[RT Sales] / 'Measure Table X'[RT Rows]
RT Sales = CALCULATE(
Sum('X'[Sales]),
'X'[Time rounded] <= Max('X'[Time rounded]))
RT Rows = CALCULATE(
COUNTA('X'[Time rounded]),
'X'[Time rounded] <= Max('X'[Time rounded]))```
I'm not sure what you are going to achive, but you can try this, this can work faster.
Average Sales =
CALCULATE(
DIVIDE('Measure Table X'[RT Sales] , 'Measure Table X'[RT Rows])
'X'[Time rounded] <= Max('X'[Time rounded]
)
RT Sales = Sum('X'[Sales])
RT Rows =COUNTA('X'[Time rounded])
I have a measure that is comprised of other measures. I will post below pictures. I am calculating the forecast for the month per location. I created a measure for that and the total is correct for that. I created another measure that calculates the working days in a month and when I divide by this measure, I get the correct results per the location but the total is wrong.
This measure shows the measure I am using to calculate the total forecast for the month per location.
"MPP = (CALCULATE(SUM('TF'[ Forecast ]), DATESBETWEEN ('TF'[Date],[Month Start-pp], [Month end_pp] )))"
This measure shows the measure I am using to calculate the working days in a month.
"Days per location =
CALCULATE (
COUNTROWS ( 'TF' ),
FILTER (
'TF',
'TF'[Date].[MonthNo] = MONTH ( TODAY () )
)
)"
The pic is showing the totaling. The first column is the measure without the division and is correct totaling. The second column is where the issue is.
I have daily sales data and I would like to create a measure or a column that calculates the monthly sales trend based on the average daily units sold in the month.
For example, as of 08/17/2017, we have had 12 working days this month and 360 units sold. This is an average of 30 units per day. So to calculate the trend manually, I would take 30 units/day and multiply it by the 23 total working days in the month for a trend of 690 units sold.
Here is some sample data.
EDIT: Adjusted the explanation and measure definitions based on the new info that was added to the post
You can create three measures to help you reaching your final result. In this example I'm merely splitting the measure into three parts to increase the readability. You can put it all together in a single measure if you like.
The first measure gives you the number of units sold. This is just a simple sum of units sold, since you have already added a month filter to your measures in your sample:
Sales:=SUM('SalesTable'[Items Sold])
The second measure gives you the number of working days for the filtered month up until the latest entry in your Sales Table:
WorkingDaysToDate:=
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[Date] > CALCULATE(MAX('SalesTable'[Date]))
&& [Type] = 'Work Day'
)
)
The third measure gives you the total number of working days for the filtered month:
WorkingDays:=
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
[Type] = 'Work Day'
)
)
In the end you can combine the three measures to get your month trend:
MonthTrend:=DIVIDE([Sales], [WorkingDaysToDate]) * [WorkingDays]
Total Month To Date Sales
TotalMTDSales = SUM('Sales Table'[Items Sold])
Total Month To Date Work Days
TotalMTDWorkDays = CALCULATE(
COUNT('DateTable'[Date]),
FILTER(ALLSELECTED('DateTable'), 'DateTable'[Date]<=MAX('SalesTable'[Date]) &&
'DateTable'[Type] = "Work Day"))
Total Work Days
TotalWorkDays = CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[Type]= "Work Day"))
Trend = ([TotalMTDSales] / [TotalMTDWorkDays] ) * [TotalWorkDays]
Filter by Month