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
arpitprakash
Helper I
Helper I

Filtered tasks based on their predecessor tasks

Example 1
IdTaskPredecessor
ST04270Task 01ST04270
ST04280Task 02ST04270
ST04300Task 03ST04270
ST04310Task 04ST04280
ST04320Task 05ST04310
ST04330Task 06ST04340
ST04340Task 07ST04320
ST04350Task 08ST04340
Ejemplo2
IdTaskPredecessor
ST04270Task 01ST04270
ST04280Task 02ST04270
ST04300Task 03ST04270
ST04310Task 04ST04280
ST04320Task 05ST04310
ST04330Task 06ST04340
ST04340Task 07ST04320
ST04350Task 08ST04340

Hello

I'm relatively new to Power BI and need help from this community to achieve the previous result. I am working with a Construction Program and my ultimate goal is to get a list of all the tasks that have been defined as its predecessors. This is to narrow down what task might be affecting my selected task from completion, upstream. I hope to get a list of all the filtered predecessor tasks, after selecting any task.

In example 1 above, if I select Task 08, you must filter task 07, which is its predecessor, Task 05, which is task 07 predecessor, and so on.

I'll really appreciate any ideas I might have to accomplish this.

Thank you!

8 REPLIES 8
v-lili6-msft
Community Support
Community Support

hi  @arpitprakash 

For your case, you could try this way as below:

Step1:

Use Path Function to create a path level column

https://docs.microsoft.com/en-us/dax/parent-and-child-functions-dax

Path level = PATH('Table'[Id],'Table'[Predecessor])

 

1.JPG

 

Step2:

You need a separate dim task table for slicer.

 

Step3:

Create a measure as below:

For visual filter = var _pathleve=CALCULATE(SELECTEDVALUE('Table'[Path level]),FILTER(ALL('Table'),'Table'[Task] in VALUES('dim Task'[Task]))) return
IF(ISFILTERED('dim Task'[Task]),IF(PATHCONTAINS(_pathleve,SELECTEDVALUE('Table'[Id])),1,0),1)

 

Step4:

Then drag [ID],[Task],[Predecessor] field into a table visual and drag this measure into visual level filter of this table and set its filter is 1.

2.JPG

Result:

3.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

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

@v-lili6-msft , a quick follow up on this > what if a Task has multiple parents? Simplified example -

 

ATask 01-
BTask 02-
CTask 03-
DTask 04B
DTask 04C
ETask 05-
FTask 06-
GTask 07D
GTask 07F
HTask 08G
ITask 09H


After a bit of research, it seems Path function and BI, in general, doesn't easily deal with multiple parent hierarchies. A few posts are talking about flattening the table using various hierarchy levels? Any idea how we can do that for my case?

Thanks again!

Anonymous
Not applicable

Let me repeat myself as you might have not notice:

"This is a recursive calculation so you should not use DAX for this as DAX does not support recursion apart from a version called "sideways recursion." You should change your data model using Power Query and then write measures against this new structure. The key to your calculation is A CHANGE OF DATA MODEL."

Best
D

@Anonymous, Sorry for not responding to you earlier, but due to my limited knowledge in this I am not sure what my data model should look like, be it through Power Query. I found the following post and am trying to understand how to replicate it for my data - 

https://www.thebiccountant.com/2017/02/14/dynamically-flatten-parent-child-hierarchies-in-dax-and-powerbi/

 

If I somehow make different hierarchy levels as columns, I will probably be able to filter them out using DAX. Is this the right approach?

 

Anonymous
Not applicable

Not sure if this flattening is going to work because this technique is normally used when you've got a parent-child hierarchy where an item has only 1 parent, not many. I have not yet seen a model where there would be many parents... but it doesn't mean it's not possible. You have to first try to adjust the known solutions to your case and if they don't work, you have to re-think your model and re-shape it.

Best
D

Thank you so much @v-lili6-msft, this is exactly what I was looking for!

Anonymous
Not applicable

This is a recursive calculation so you should not use DAX for this as DAX does not support recursion apart from a version called "sideways recursion." You should change your data model using Power Query and then write measures against this new structure. The key to your calculation is A CHANGE OF DATA MODEL.

Best
D
mahoneypat
Employee
Employee

Try this measure out with the Task field in a table visual.  I put your data in a table called 'Tasks' and wrote this measure that seems to do what you are looking for.  The key is passing the selected predecessor IDs to the IDs column with TREATAS().  This should work too if each task had multiple rows with different parent tasks (that's why I used Concatenatex() function).

 

Predecessors = var selectedtask = SELECTEDVALUE(Tasks[Task])
var selectedpredecssors = VALUES(Tasks[Predecessor])
var predecessors = CALCULATETABLE(VALUES(Tasks[Task]), All(Tasks), TREATAS(selectedpredecssors, Tasks[Id]))
return CONCATENATEX(predecessors, Tasks[Task], "; ")
 
tasks.png
If this works for you, please mark it as the solution.  Kudos are also appreciated.  Please let me know if not.
Regards,
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.