I have the following table:
I need the units per hour to countDistinct by the individual date, but average when it is roleld up into the month. My current measure is:
unitsPerHour =
DIVIDE(
SUM('Workmax Time - Open and Batched'[units]),
SUM('Workmax Time - Open and Batched'[totalHours])
)
How can I update this expression to reflect this?
I figured it out. Posting for others for future reference.
crewSizeWAvg =
CALCULATE (
AVERAGEX (
VALUES ( 'Workmax Time - Open and Batched'[inTimeDateRawDateOnly] ),
CALCULATE ( DISTINCTCOUNT ( 'Workmax Time - Open and Batched'[employee_id] ) )
))
Related
I have a running total in power BI as a line graph.
I want to only show my running total line up to the most recent months data (september 22), in order to get the flat line off the visualisation, so I can forecast the rest of the line.
My cumulative total measure is :
'''Actual Spend YTD =
CALCULATE (
SUM ( CombinedUsageFact[TargetCost] ),
FILTER (
ALLSELECTED ( MonthNumDim[DateMonth]),
ISONORAFTER ( MonthNumDim[DateMonth], MAX ( MonthNumDim[DateMonth] ), DESC )
)
)'''
I need my axis to display up to year end (march 2023) like it does.
What can I do to stop my cumulative line at the most recent data?
Thanks
Would attach images/sample but it says there's a problem with the server!
To get the cumulative calculation to stop on the last period with data, filter the last date by the fact table:
Actual Spend YTD =
VAR maxDate =
CALCULATE ( MAX ( MonthNumDim[DateMonth] ), CombinedUsageFact )
RETURN
CALCULATE (
SUM ( CombinedUsageFact[TargetCost] ),
FILTER (
ALLSELECTED ( MonthNumDim[DateMonth] ),
ISONORAFTER ( MonthNumDim[DateMonth], maxDate, DESC )
)
I am trying to use a calculate statement with a measure to filter results of a table but I need the values to change if the user selects 1 date from a slicer. Below is the code I am using.
PCurrentDay = calculate(sum('Sheet0 (2)'[Toys_Count]),datediff('Sheet0 (2)'[SCAN_Date],'Sheet0 (2)'[SHIP_Date],DAY)=0)
This returns a value but it won't update if the user selects a specific scan date. Any ideas?
Can you replace the measure with following
Measure =
CALCULATE (
SUM ( 'Table'[val] ),
FILTER (
'Table',
DATEDIFF (
CALCULATE ( MAX ( 'Table'[scan] ) ),
CALCULATE ( MAX ( 'Table'[ship] ) ),
DAY
) = 0
)
)
CALCULATE inside DATEDIFF provides the correct context for the filter to work.
I'm trying to figure out how to create a cumulative line graph in Power BI. The problem I'm having is I have a lot of variables that need to fit in and I'm having some trouble to make it work. I've got the following columns in a table.
Product certification
Delivery date
Product volume
The product volume column has an associated data and certification number to each volume row. I want to create a graph that has cumulative lines for each product certification.
To create the cumulative graph by volume I've written a DAX formula that goes like this:
Cumulative volume =
CALCULATE (
SUM ( CONCRETE[Product Volume] ),
FILTER (
ALL ( CONCRETE ),
CONCRETE[Delivery Date] <= MAX ( CONCRETE[Delivery Date] )
)
)
However, this doesn't account for the Product certification. It only sums up the total volume to date.
Anyone have any thoughts on how to correct this?
Thanks so much for any help!
Just use Date column while filtering for ALL,
Cumulative volume =
CALCULATE (
SUM ( CONCRETE[Product Volume] ),
FILTER (
ALL ( CONCRETE[Delivery Date] ),
CONCRETE[Delivery Date] <= MAX ( CONCRETE[Delivery Date] )
)
)
I hope it helps!!
My table represents users working on a production line. Each row in the table provides the number of units a user produced within a 15 minute window. I am trying to calculate Units/Hour per User (which seems to be working fine), but my overall Average seems to be off.
Table and results of my measure:
Row by row it is what I am looking for. But the total average of 179.67 is wrong. It should be 196. I think for the 11:30 timestamp, Leondro did not have any work, and it is including a 0 for him. I would like to exclude that.
Measure:
UPH =
var unitshour = CALCULATE(SUM(Table1[Units]) / (DISTINCTCOUNT(Table1[DateTime])/4))
var users = AVERAGEX( VALUES(Table1[DateTime]), DISTINCTCOUNT(Table1[Username]))
RETURN
unitshour/ users
I don't think 196 is the number you want if you want to treat each time period equally. I'd suggest this alternative:
UPH =
AVERAGEX (
VALUES ( Table1[DateTime] ),
CALCULATE ( 4 * SUM ( Table1[Units] ) / DISTINCTCOUNT ( Table1[Username] ) )
)
If you want each time period to be weighted by the number of users in that time period, then the 196 it what you want.
UPHUserWeighted =
VAR Summary =
SUMMARIZE (
Table1,
Table1[DateTime],
Table1[Username],
"UPH", 4 * SUM ( Table1[Units] ) / DISTINCTCOUNT ( Table1[Username] )
)
RETURN AVERAGEX ( Summary, [UPH] )
I have a measure calculated in the context of a selected month defined as:
MyMetric = COUNTROWS ( FILTER ( Entities, [Incident Count] > [Target] ) )
I need to calculate the YTD number while calculating each month separately. This is because a single Entity that exceeds the Target in two months needs to be counted twice, whereas a simple YTD calculation would only include it once. For example, when reporting March, a correct result is achieved with:
[MyMetric YTD] = [MyMetric]
+ CALCULATE ([MyMetric] , DATEADD(DateTable[Date], -1 , MONTH))
+ CALCULATE ([MyMetric] , DATEADD(DateTable[Date], -2 , MONTH))
Obviously, this is not the right way to do it. How can this kind of calculation be written efficiently?
Let's suppose that you have a Month column in your DateTable. If not, then you can create one.
Then you can try something along these lines:
MyMetric YTD
= SUMX(
CALCULATETABLE(
VALUES( DateTable[Month] ),
DATESYTD( DateTable[Date] )
),
[MyMetric]
)
Basically, you get a list of each month in the year so far and then sum your measure value for each one of those months.