Forum Discussion
Ilse_ScpDt
Helper I
4 years agoCalculate difference per timeslot
Hi there, I am only familiair with simple dax so I am not sure how to calculate the following: The difference between two values (a measure and a column) for every timeslot. The thing is,...
- 4 years ago
Hi Ilse_ScpDt
You need to create a variable table in the measure to get the PM_Diff for every Timeslot. The variable table should be in the format of the sample table you showed in the original post. Then filter the variable table and count its positive and negative differences.
Below are sample codes for your reference. The difficulty might be at creating the variable table. You may need to modify your code for PM_Needed, PM_Present and PM_Diff according to your model.
Positive = VAR vTable = ADDCOLUMNS ( SUMMARIZE ( 'Dim_Time', 'Dim_Time'[TimeSlot], "__PMNeeded", [PM_Needed], "__PMPresent", SUM ( 'Fact_Staff'[PM_present] ) ), "__PMDiff", [__PMPresent] - [__PMNeeded] ) RETURN COUNTROWS ( FILTER ( vTable, [__PMDiff] > 0 ) )Negative = VAR vTable = ADDCOLUMNS ( SUMMARIZE ( 'Dim_Time', 'Dim_Time'[TimeSlot], "__PMNeeded", [PM_Needed], "__PMPresent", SUM ( 'Fact_Staff'[PM_present] ) ), "__PMDiff", [__PMPresent] - [__PMNeeded] ) RETURN COUNTROWS ( FILTER ( vTable, [__PMDiff] < 0 ) )Hope this helps.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Ilse_ScpDt
Helper I
4 years agoNow using this to sum PM_needed:
SumPM_Needed =
SUMX(
FILTER(
ALL(DIM_Time),
DIM_Time[TimeSlot] <= MAX(DIM_Time[TimeSlot])
),
[PM_Needed]
)
Still wondering how to get the positive and negative differences separately.