Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Most Recent Completed/Open Transaction Flag Per Store

The goal is to flag the most recent Completed or Open Transaction for each store filtering for a specific product code (product_code = CP - 545). My current output is successful at flagging the most ...
  • v-easonf-msft's avatar
    5 years ago

    Hi, Anonymous 

    Try to create calculated columns as below:

    Sub_flag = 
    VAR T1 =
        FILTER ( 'Table', 'Table'[store_id] = EARLIER ( 'Table'[store_id] ) )
    RETURN
        // IF (
        //     CONTAINS ( T1, 'Table'[product_code], "CP - 545" ),
            IF (
                'Table'[Date]
                    = MAXX (
                        FILTER (
                            T1,
                            'Table'[status_bucket] = "Completed"
                                && 'Table'[product_code] = "CP - 545"
                        ),
                        'Table'[Date]
                    ),
                1,
                IF (
                    'Table'[Date]
                        = MAXX (
                            FILTER (
                                T1,
                                'Table'[status_bucket] = "Outstanding"
                                    && 'Table'[product_code] = "CP - 545"
                            ),
                            'Table'[Date]
                        ),
                2
                )
            )
        // )
    Result_flag = 
    VAR T1 =
        FILTER ( 'Table', 'Table'[store_id] = EARLIER ( 'Table'[store_id] ) )
    RETURN
        IF (
            'Table'[Sub_flag]=MINX(
                        FILTER (
                            T1,
                            'Table'[product_code] = "CP - 545"
                        ),
                        'Table'[Sub_flag]
                    ),
                1
        )
    

    Result:

    Please check my sample file for more details.

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.