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])
Related
I'm using Power BI, in directQuery mode for all my tables (other than my date table).
I can't change that.
To simplify, I have a fact table that has an id, a date field and a sales figure (not even using the sales for this question.. just the fact that there is a sale on this date).
The date field relates to my date dimension as you'd expect.
I have created a measure, which is a rolling 2 year count of sales (not sum, just count).
Rolling_year_sales_count = CALCULATE(
DISTINCTCOUNT( fact[sale_id]),
DATESINPERIOD(
dim_date[yyyy_mm_dd],
LASTDATE(dim_date[yyyy_mm_dd]),
-2,
Year
))
this looks good when I put it on a simple table - its properly counting the rolling year counts.
Now, I want to create a rolling 2 year AVERAGE count.
So the result should show 2 for 1925, 5 for 1926, 8 for 1927... (Add the 2 previous year's rolling counts, and divide by 2)
I tried just including this measure in a new measure that uses SUMMARIZE - but because I am using DirectQuery, I cannot refer to calculated measures in my SUMMARIZE.. Same goes for CALCULATE.
So how can I calculate this average, knowing that I'm in directQuery mode?
Thanks!
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 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 a table in PowerBI that has the column "Date" and "Sales". I want to create a measure and display it in a table that computes a rolling 7 day total of the "Sales" column. To be clear, I want to see this overtime, I do not want it for a single day, I want to create a table exactly like I am showing below, thanks!
Rolling total can be make using the quick measure feature underneath the New Measure & New Column buttons in the Home Tab.
Select Calculation -> Rolling Total in the Totals Section
If not then you can make a formula (Both for Measures):
Rolling Total =
CALCULATE(
SUM('Sheet1'[Sales]),
FILTER(
ALLSELECTED('Sheet1'[Date]),
ISONORAFTER('Sheet1'[Date], MAX('Sheet1'[Date]), DESC)
)
)
Rolling Total 2 =
CALCULATE(
SUM(Sheet1[Sales]),
DATESMTD(
Sheet1[Date])
)
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