Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
win_anthony
Resolver III
Resolver III

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 recent Completed transaction for each store for a specific product code. The problem is that the current output will not recognize/flag the most recent Open transaction if it is not Completed for the store and specific product code. Below you will find: current Calculated Column DAX, Current Output sample data, Expected Output sample data

 

Any advice on how to update my calculated column to flag both the most recent Completed or Open transaction for each store filtering for a specific product code (product_code = CP - 545) will be greatly appreciated.

 

Current Calculated Column DAX

 

 

latest_complete_welcome_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]), 1 )
)

 

 

Current Output sample data  (Notice Store_ID = 4 >>> does NOT flag for trans_id = 114 >> current Calculated Column DAX is missing this)

store_idtrans_idproduct_codeproductstatusstatus_bucketdatelatest_complete_welcome_flag
1100CP - 545Welcome LetterNewOutstanding20-Oct-20 
1101CP - 545Welcome LetterNewOutstanding5-Jan-21 
1100CP - 545Welcome LetterIn ProgressOutstanding6-Jan-21 
1100CP - 545Welcome LetterCompleteCompleted7-Jan-211
2102CP - 452BurgerNewOutstanding1-Nov-20 
2103CP - 528PizzaNewOutstanding1-Nov-20 
2104CP - 545Welcome LetterNewOutstanding1-Nov-20 
2105CP - 532WingsNewOutstanding1-Nov-20 
2103CP - 528PizzaCompleteCompleted2-Nov-20 
2104CP - 545Welcome LetterIn ProgressOutstanding11-Nov-201
3105CP - 545Welcome LetterNewOutstanding9-Feb-21 
3106CP - 545Welcome LetterNewOutstanding15-Feb-21 
3105CP - 545Welcome LetterCompleteCompleted10-Feb-21 
3107CP - 545Welcome LetterNewOutstanding22-Feb-21 
3106CP - 545Welcome LetterCompleteCompleted17-Feb-211
3108CP - 545Welcome LetterNewOutstanding16-Feb-21 
3109CP - 545Welcome LetterNewOutstanding19-Feb-21 
3110CP - 545Welcome LetterNewOutstanding1-Mar-21 
4111CP - 545Welcome LetterNewOutstanding28-Feb-21 
4112CP - 532WingsNewOutstanding28-Feb-21 
4113CP - 545Welcome LetterNewOutstanding5-Mar-21 
4111CP - 545Welcome LetterIn ProgressOutstanding1-Mar-21 
4114CP - 545Welcome LetterNewOutstanding20-Mar-21 

Expected Output sample data (Notice Store_ID = 4 >>> YES flag for trans_id = 114 >> hoping to update current Calculated Column DAX to include this)

store_idtrans_idproduct_codeproductstatusstatus_bucketdatelatest_complete_welcome_flag
1100CP - 545Welcome LetterNewOutstanding20-Oct-20 
1101CP - 545Welcome LetterNewOutstanding5-Jan-21 
1100CP - 545Welcome LetterIn ProgressOutstanding6-Jan-21 
1100CP - 545Welcome LetterCompleteCompleted7-Jan-211
2102CP - 452BurgerNewOutstanding1-Nov-20 
2103CP - 528PizzaNewOutstanding1-Nov-20 
2104CP - 545Welcome LetterNewOutstanding1-Nov-20 
2105CP - 532WingsNewOutstanding1-Nov-20 
2103CP - 528PizzaCompleteCompleted2-Nov-20 
2104CP - 545Welcome LetterIn ProgressOutstanding11-Nov-201
3105CP - 545Welcome LetterNewOutstanding9-Feb-21 
3106CP - 545Welcome LetterNewOutstanding15-Feb-21 
3105CP - 545Welcome LetterCompleteCompleted10-Feb-21 
3107CP - 545Welcome LetterNewOutstanding22-Feb-21 
3106CP - 545Welcome LetterCompleteCompleted17-Feb-211
3108CP - 545Welcome LetterNewOutstanding16-Feb-21 
3109CP - 545Welcome LetterNewOutstanding19-Feb-21 
3110CP - 545Welcome LetterNewOutstanding1-Mar-21 
4111CP - 545Welcome LetterNewOutstanding28-Feb-21 
4112CP - 532WingsNewOutstanding28-Feb-21 
4113CP - 545Welcome LetterNewOutstanding5-Mar-21 
4111CP - 545Welcome LetterIn ProgressOutstanding1-Mar-21 
4114CP - 545Welcome LetterNewOutstanding20-Mar-211
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @win_anthony 

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:

6.png

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.

View solution in original post

1 REPLY 1
v-easonf-msft
Community Support
Community Support

Hi, @win_anthony 

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:

6.png

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.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.