Forum Discussion

elietech's avatar
elietech
Helper II
5 years ago
Solved

Transform and summarize data from one table into another...

Ok, here is the problem I am faced with.     I have a data set that records everytime a piece of equipment is removed from service for being unserviceable, and records the time it went "DOWN" (remo...
  • MFelix's avatar
    MFelix
    5 years ago

    Hi elietech .

     

    The error was related with the calculation when you have a single day, I already fixed it by changing the formula to:

    measure = 
    VAR Date_Selection =
        MAX ( 'Dates'[Date] )
    VAR Date_Selection_Next = Date_Selection + 1
    VAR temp_table =
        FILTER (
            ADDCOLUMNS (
                UpDown;
                "Start";
                    DATE ( YEAR ( UpDown[DOWN_START] ); MONTH ( UpDown[DOWN_START] ); DAY ( UpDown[DOWN_START] ) );
                "End";
                    DATE ( YEAR ( UpDown[DOWN_STOP] ); MONTH ( UpDown[DOWN_STOP] ); DAY ( UpDown[DOWN_STOP] ) )
            );
            [Start] <= Date_Selection
                && [End] >= Date_Selection
        )
    VAR DateStart =
        IF (
            MINX ( temp_table; UpDown[DOWN_START] ) <= Date_Selection;
            Date_Selection;
            MINX ( temp_table; UpDown[DOWN_START] )
        )
    VAR DateEnd =
        IF (
            MAXX ( temp_table; UpDown[DOWN_STOP] ) >= Date_Selection_Next;
            Date_Selection_Next;
            MAXX ( temp_table; UpDown[DOWN_STOP] )
        )
    VAR Same_day_selection =
        IF (
            MAXX ( temp_table; [Start] ) = MINX ( temp_table; [End] )
                && MINX ( temp_table; UpDown[DOWN_START] ) >= Date_Selection;
            1
        )
    RETURN
        IF (
            DateEnd = BLANK ();
            1440;
            IF (
                Same_day_selection = BLANK ();
                DATEDIFF ( Date_Selection; DateStart; MINUTE )
                    + DATEDIFF ( DateEnd; Date_Selection_Next; MINUTE );
                1440
                    - CALCULATE (
                        SUM ( UpDown[DOWN_DURATION] );
                        FILTER ( temp_table; UpDown[DOWN_START] = DateStart )
                    )
            )
        )

     

    Check result below and attach.