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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NPC
Helper I
Helper I

Create a new column based on conditions being met

Hi Everyone,

 

I have a table like this:

Item #CodeTask
123457ST
123458CR
123459RW
1234510CR
123463ST
123464CR

 

Basically the goal is to end up with another column (Open ST) that will only show open STs. Open STs are determined by NOT having Task RW anywhere after ST.

 

End goal:

Item #CodeTaskOpen ST
123457ST 
123458CR 
123459RW 
1234510CR 
123463STST
123464CR 

 

So in this case Item # 12346 will end up with ST because there is no Task RW anywhere after Task ST. Item # 12345 won't be an open ST because RW is present somewhere after ST.

As you can see, other Tasks can be present after ST but that's not necessarily relevant as I care about the Tasks ST and RW.

 

Any thoughts on how I can code this. 

 

Thanks in advance!

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

Open ST = if(Data[Task]="ST",if(CALCULATE(COUNTROWS(Data),FILTER(data,Data[Item #]=EARLIER(Data[Item #])&&Data[Code]>EARLIER(Data[Code])&&Data[Task]="RW"))>0,BLANK(),Data[Task]),BLANK())

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
NPC
Helper I
Helper I

@Greg_Deckler    thank you. I haven't tried your solution because I found one that works already. I'm confident it will work too. Thanks for taking the time to work on this. 

Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

Open ST = if(Data[Task]="ST",if(CALCULATE(COUNTROWS(Data),FILTER(data,Data[Item #]=EARLIER(Data[Item #])&&Data[Code]>EARLIER(Data[Code])&&Data[Task]="RW"))>0,BLANK(),Data[Task]),BLANK())

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur , thank you! This works. Really appreaciate taking the time. 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CNENFRNL
Community Champion
Community Champion

For fun only, a showcase of powerful Excel worksheet formula,

CNENFRNL_1-1664663511890.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

hnguy71
Super User
Super User

@NPC,

Can you see if this fits your criteria?

Open ST = 

VAR _GetAllTasks = CALCULATE(CONCATENATEX(NPC, [Task], "|"), FILTER(NPC, NPC[Item #] = EARLIER(NPC[Item #])))
VAR _Exclude = "RW"
VAR _Include = "ST"

RETURN

SWITCH( TRUE(),
    SEARCH(_Exclude, _GetAllTasks, 1, 0) > 0, BLANK(),
    SEARCH(_Include, _GetAllTasks, 1, 0) > 0 && [Task] = _Include, _Include
)

 

hnguy71_0-1664651008264.png

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

@hnguy71 thank you. I haven't tried your solution because I found one that works already but all indications are that this would work too. Thanks for taking the time to work on this. 

Greg_Deckler
Community Champion
Community Champion

@NPC Try:

Open ST = 
    VAR __Item = [Item #]
    VAR __Code = [Code]
    VAR __Table = FILTER('Table',[Code] > __Code && [Item #] = __Item && [Task] = "RW")
RETURN
    IF([Task] = "ST" && COUNTROWS(__Table)<1, "ST", BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors