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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chriser
Frequent Visitor

Check value against entire column and return value once it occurred first time

Hi, 

 

I need to look through entire column and as soon as "TheOrder" value is found in OrderNumber column, Result will always return Special from then on against this specific CustomerID, regardless if consecutive order numbers are Normal or TheOrder.

 

Example:

 

CustomerID    OrderNumber        Result

1                     Normal                   Basic

2                     Normal                   Basic

1                     TheOrder                Special

3                     Normal                   Basic

1                     Normal                   Special

2                     TheOrder                Special

3                     TheOrder                Special

1                     TheOrder                Special

1                     Normal                   Special

 

 

Thanks in advance!

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @chriser ,

 

It is nearly impossible to make result return special only when the order number occur “the order” unless your data have an increment primary column or a date key than can indicate the sequence of the orderNmuber.

 

Result =
VAR i = [Customer ID]
VAR time = [Date Key]
VAR t =
    FILTER ( 'ExampleWithTime', 'ExampleWithTime'[Customer ID] = i )
VAR t_order =
    FILTER ( t, [OrderNumber] = "TheOrder" )
VAR firstTime =
    MINX ( t_order, [Date Key] )
VAR specialStatus =
    COUNTROWS ( t_order ) > 0
RETURN
IF ( specialStatus, IF ( time >= firstTime, "Special", "Basic" ), "Basic" )

 

Check-value-against-entire-column-and-return-value-once-it-1.png

 

Or if you do not have such a column, we can go to power query editor to create an index column.

 

Check-value-against-entire-column-and-return-value-once-it-2.png

 

After creating index column, we can create a calculated column similar to the previous one to meet your requirement.

 

Result =
VAR i = [Customer ID]
VAR index = [Index]
VAR t =
    FILTER ( 'Example', 'Example'[Customer ID] = i )
VAR t_order =
    FILTER ( t, [OrderNumber] = "TheOrder" )
VAR firstIndex =
    MINX ( t_order, [Index] )
VAR specialStatus =
    COUNTROWS ( t_order ) > 0
RETURN
    IF ( specialStatus, IF ( index >= firstIndex, "Special", "Basic" ), "Basic" )

 

Check-value-against-entire-column-and-return-value-once-it-3.png

 

BTW, pbix as attached.

 

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

Community Support Team _ Dong Li
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

2 REPLIES 2
v-lid-msft
Community Support
Community Support

Hi @chriser ,

 

It is nearly impossible to make result return special only when the order number occur “the order” unless your data have an increment primary column or a date key than can indicate the sequence of the orderNmuber.

 

Result =
VAR i = [Customer ID]
VAR time = [Date Key]
VAR t =
    FILTER ( 'ExampleWithTime', 'ExampleWithTime'[Customer ID] = i )
VAR t_order =
    FILTER ( t, [OrderNumber] = "TheOrder" )
VAR firstTime =
    MINX ( t_order, [Date Key] )
VAR specialStatus =
    COUNTROWS ( t_order ) > 0
RETURN
IF ( specialStatus, IF ( time >= firstTime, "Special", "Basic" ), "Basic" )

 

Check-value-against-entire-column-and-return-value-once-it-1.png

 

Or if you do not have such a column, we can go to power query editor to create an index column.

 

Check-value-against-entire-column-and-return-value-once-it-2.png

 

After creating index column, we can create a calculated column similar to the previous one to meet your requirement.

 

Result =
VAR i = [Customer ID]
VAR index = [Index]
VAR t =
    FILTER ( 'Example', 'Example'[Customer ID] = i )
VAR t_order =
    FILTER ( t, [OrderNumber] = "TheOrder" )
VAR firstIndex =
    MINX ( t_order, [Index] )
VAR specialStatus =
    COUNTROWS ( t_order ) > 0
RETURN
    IF ( specialStatus, IF ( index >= firstIndex, "Special", "Basic" ), "Basic" )

 

Check-value-against-entire-column-and-return-value-once-it-3.png

 

BTW, pbix as attached.

 

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

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

Thank you @v-lid-msft !

 

I do have a date column in my table so your soultion works really well. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.