Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi,
I have two tables one contains tasks & other has store & departments linked by parent_id column
for example:
Store table:
| Name | ID | Parent ID | Type |
| Store 1 | 1 | Store | |
| Department A | 2 | 1 | Department |
| Department B | 3 | 1 | Department |
Task Table:
| Name | ID | OwningStoreID | Status |
| Task A | 1 | 1 | Open |
| Task B | 2 | 2 | Completed |
| Task C | 3 | 3 | Open |
I want to create a measure to count all tasks opened for a store & all tasks open in the descendant departments. Which means to show count 3 for store 1
How could I do this? Thanks!
Solved! Go to Solution.
Hi @Bassant_Saied , one of the ways is to use hierarchies. For that a number of calculated columns and measures need to be created.
Calculated columns in the Store table:
FullPath = PATH( Store[ID], Store[Parent ID])Level1 = LOOKUPVALUE(Store[Name], Store[ID], PATHITEM(Store[FullPath], 1, INTEGER))Level2 = IF(PATHLENGTH(Store[FullPath]) >= 2, LOOKUPVALUE(Store[Name], Store[ID], PATHITEM(Store[FullPath], 2, INTEGER)), Store[Level1])NodeDepth = PATHLENGTH(Store[FullPath])IsLeaf =
VAR c_id = Store[ID]
VAR depsAtParentLevel = CALCULATE ( COUNTROWS ( Store ), ALL ( Store ), Store[Parent ID] = c_id )
RETURN
depsAtParentLevel = 0Measures:
tasks = COUNTROWS(Task)Tasks amt =
VAR check = MAX ( Store[NodeDepth] ) + 1 < [BrowseDepth]
VAR extraLevel = MAX ( Store[NodeDepth] ) + 1 = [BrowseDepth]
VAR amt = [tasks]
VAR hasData = NOT ISBLANK ( amt )
VAR leaf = SELECTEDVALUE ( Store[IsLeaf], FALSE () )
VAR result = IF ( NOT check, IF ( extraLevel, IF ( NOT leaf && hasData, amt ), amt ) )
RETURN
IF ( MAX ( Store[NodeDepth] ) < [BrowseDepth], BLANK (), result )If you want to show the amount of tasks per store itself as well:
Tasks amt =
VAR check = MAX ( Store[NodeDepth] ) + 1 < [BrowseDepth]
VAR extraLevel = MAX ( Store[NodeDepth] ) + 1 = [BrowseDepth]
VAR amt = [tasks]
VAR hasData = NOT ISBLANK ( amt )
VAR leaf = SELECTEDVALUE ( Store[IsLeaf], FALSE () )
VAR result = IF ( NOT check, IF ( extraLevel, IF ( NOT leaf && hasData, amt ), amt ) )
RETURN
result
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
Thanks @ERD for your solution.
Actually there is also another simpler solution using Path functions. I created a ne column called PathStore with has the Path value for each store & his parents. My problem was whenever store is filtered the count of tasks rows are filtered too. So I use this formula:
VAR SelectedStore = SELECTEDVALUE ( task[owningStoreID] )
VAR TotalTasks = CALCULATE (
COUNTROWS(task),
FILTER(ALL(task),
PATHCONTAINS (task[PathStore], SelectedBU)
)
)
Hi @Bassant_Saied , one of the ways is to use hierarchies. For that a number of calculated columns and measures need to be created.
Calculated columns in the Store table:
FullPath = PATH( Store[ID], Store[Parent ID])Level1 = LOOKUPVALUE(Store[Name], Store[ID], PATHITEM(Store[FullPath], 1, INTEGER))Level2 = IF(PATHLENGTH(Store[FullPath]) >= 2, LOOKUPVALUE(Store[Name], Store[ID], PATHITEM(Store[FullPath], 2, INTEGER)), Store[Level1])NodeDepth = PATHLENGTH(Store[FullPath])IsLeaf =
VAR c_id = Store[ID]
VAR depsAtParentLevel = CALCULATE ( COUNTROWS ( Store ), ALL ( Store ), Store[Parent ID] = c_id )
RETURN
depsAtParentLevel = 0Measures:
tasks = COUNTROWS(Task)Tasks amt =
VAR check = MAX ( Store[NodeDepth] ) + 1 < [BrowseDepth]
VAR extraLevel = MAX ( Store[NodeDepth] ) + 1 = [BrowseDepth]
VAR amt = [tasks]
VAR hasData = NOT ISBLANK ( amt )
VAR leaf = SELECTEDVALUE ( Store[IsLeaf], FALSE () )
VAR result = IF ( NOT check, IF ( extraLevel, IF ( NOT leaf && hasData, amt ), amt ) )
RETURN
IF ( MAX ( Store[NodeDepth] ) < [BrowseDepth], BLANK (), result )If you want to show the amount of tasks per store itself as well:
Tasks amt =
VAR check = MAX ( Store[NodeDepth] ) + 1 < [BrowseDepth]
VAR extraLevel = MAX ( Store[NodeDepth] ) + 1 = [BrowseDepth]
VAR amt = [tasks]
VAR hasData = NOT ISBLANK ( amt )
VAR leaf = SELECTEDVALUE ( Store[IsLeaf], FALSE () )
VAR result = IF ( NOT check, IF ( extraLevel, IF ( NOT leaf && hasData, amt ), amt ) )
RETURN
result
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 14 | |
| 8 | |
| 8 | |
| 8 |