Forum Discussion

ps92's avatar
ps92
Frequent Visitor
2 years ago
Solved

Need help with logging date and information

Hello all, I have a date column, a category column and a value column. I want to be able to sum the value column with the previous column only, and if the sum is 2 (the value can be 1 or 0 for the...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi ps92 ,

     

    I suggest you to add an [Index] column in your table. Then create a measure.

    Measure = 
    VAR _STEP1 =
        ADDCOLUMNS (
            ALL ( 'Table' ),
            "Last0Date",
                IF (
                    'Table'[Below Target] = 0,
                    BLANK (),
                    CALCULATE (
                        MIN ( 'Table'[Date] ),
                        FILTER (
                            ALLEXCEPT ( 'Table', 'Table'[Section] ),
                            'Table'[Date] > EARLIER ( 'Table'[Date] )
                                && 'Table'[Below Target] = 0
                        )
                    )
                )
        )
    VAR _STEP2 =
        ADDCOLUMNS (
            _STEP1,
            "Running Total",
                SUMX (
                    FILTER (
                        _STEP1,
                        [Date] <= EARLIER ( [Date] )
                            && [Section] = EARLIER ( [Section] )
                            && [Last0Date] = EARLIER ( [Last0Date] )
                    ),
                    [Below Target]
                )
        )
    RETURN
        MAXX ( FILTER ( _STEP2, [Index] = MAX ( 'Table'[Index] ) ), [Running Total] )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.