Forum Discussion

Ilse_ScpDt's avatar
Ilse_ScpDt
Icon for Helper I rankHelper I
4 years ago
Solved

Calculate 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,...
  • v-jingzhang's avatar
    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.