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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
aJ2
Helper I
Helper I

Flag against orders which were placed when a code was run

Hi.

 

I have a table of orders where the revenue, coupon used, validity period etc is mentioned. There are some instances wherein the on the days coupons were run, in some orders no coupon was used.

 

For example,

dateorder idtotal valuecoupon codecoupon valid fromcoupon valid till
23-Dec-171001100MC1023-Dec-1724-Dec-17
23-Dec-17100232MC1023-Dec-1724-Dec-17
23-Dec-171003342   
23-Dec-1710043534MC1023-Dec-1724-Dec-17
23-Dec-171005596MC1023-Dec-1724-Dec-17
23-Dec-17100650   
24-Dec-17100743   
24-Dec-171008564MC1023-Dec-1724-Dec-17
24-Dec-17100931   
24-Dec-1710103265MC1023-Dec-1724-Dec-17
24-Dec-1710119956   
24-Dec-171012213MC1023-Dec-1724-Dec-17
24-Dec-171013635MC1023-Dec-1724-Dec-17
25-Dec-17101445   
25-Dec-171015646   
25-Dec-171016458   
25-Dec-17101798   

 

So I want a new column to identify if a coupon code has been used on that day. So against order id 1009, I want True against it as the order has been placed during the time a coupon code is running.

 

Kindly guide

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@aJ2,

Please create the following columns in your table.

Index = RANKX(FILTER(Table1,Table1[order id]<EARLIER(Table1[order id])),Table1[order id],,ASC)
prefromdate = 
VAR LastNonBlankIndex =
    CALCULATE (
        LASTNONBLANK ( Table1[Index], 1 ),
        FILTER (
            ALL ( Table1 ),
           Table1[Index] <= EARLIER ( Table1[Index] )
                && NOT ( ISBLANK ( Table1[coupon valid from]) )
        )
    )
RETURN
    CALCULATE (
        MAX(Table1[coupon valid from]),
        FILTER ( ALL ( Table1 ), Table1[Index] = LastNonBlankIndex)
    )
pretodate = 
VAR LastNonBlankIndex =
    CALCULATE (
        LASTNONBLANK ( Table1[Index], 1 ),
        FILTER (
            ALL ( Table1 ),
           Table1[Index] <= EARLIER ( Table1[Index] )
                && NOT ( ISBLANK ( Table1[coupon valid from]) )
        )
    )
RETURN
    CALCULATE (
        MAX(Table1[coupon valid till]),
        FILTER ( ALL ( Table1 ), Table1[Index] = LastNonBlankIndex )
    )
check = IF(AND(Table1[date]<=Table1[pretodate],Table1[date]>=Table1[prefromdate])&&Table1[coupon code]=BLANK(),TRUE())

1.PNG

Regards,
Lydia

Community Support Team _ Lydia Zhang
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-yuezhe-msft
Employee
Employee

@aJ2,

Please create the following columns in your table.

Index = RANKX(FILTER(Table1,Table1[order id]<EARLIER(Table1[order id])),Table1[order id],,ASC)
prefromdate = 
VAR LastNonBlankIndex =
    CALCULATE (
        LASTNONBLANK ( Table1[Index], 1 ),
        FILTER (
            ALL ( Table1 ),
           Table1[Index] <= EARLIER ( Table1[Index] )
                && NOT ( ISBLANK ( Table1[coupon valid from]) )
        )
    )
RETURN
    CALCULATE (
        MAX(Table1[coupon valid from]),
        FILTER ( ALL ( Table1 ), Table1[Index] = LastNonBlankIndex)
    )
pretodate = 
VAR LastNonBlankIndex =
    CALCULATE (
        LASTNONBLANK ( Table1[Index], 1 ),
        FILTER (
            ALL ( Table1 ),
           Table1[Index] <= EARLIER ( Table1[Index] )
                && NOT ( ISBLANK ( Table1[coupon valid from]) )
        )
    )
RETURN
    CALCULATE (
        MAX(Table1[coupon valid till]),
        FILTER ( ALL ( Table1 ), Table1[Index] = LastNonBlankIndex )
    )
check = IF(AND(Table1[date]<=Table1[pretodate],Table1[date]>=Table1[prefromdate])&&Table1[coupon code]=BLANK(),TRUE())

1.PNG

Regards,
Lydia

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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