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
JensV
Regular Visitor

Count Projects within ProjectStatus and ProjectType

Hi there.

I have a big challenge I hope you can help me with. I have a Table that track e.g. project status together with a lot other information about the project.

 

I would look like this:

 

DateProjectIDProjectStatus ProjectType
19-11-2017100ActiveGroupeA
19-11-2017200ActiveGroupeB
20-11-2017300ActiveGroupeB
20-11-2017100ActiveGroupeA
20-11-2017200On-HoldGroupeB
.   
.   
19-12-2017100ClosedGroupeA

 

What I whould like to to is to count the number of Projects within Both ProjectStatus and ProjectGroup. It is however also, important that i only count the project once. By this means, if my date slice has the value 19-112017 By table would look like this:

ProjectTypsActiveClosedOnhold
GroupA1  
GroupB1  

 

However, if I select the whole time period 19-11-2017 - 19-12-2017 my table should look like this. 

ProjectTypsActiveClosedOnhold
GroupA 1 
GroupB1 1

 

I hope you can help me.

 

1 ACCEPTED SOLUTION
technolog
Super User
Super User

To get the desired result, you can use DAX to create measures that perform these calculations. Here are the steps and DAX measures you can create.

Unique Projects:
Firstly, create a table that captures unique projects over the entire duration:
UniqueProjects = SUMMARIZE('TableName', 'TableName'[ProjectID], LASTNONBLANK('TableName'[Date], 1), 'TableName'[ProjectStatus], 'TableName'[ProjectType])
This formula creates a new table, UniqueProjects, which summarizes the original table by ProjectID, and captures the latest status and type for each unique project.

Active Projects:
Now, create a measure to count active projects:
Active Projects =
COUNTROWS(
FILTER(
UniqueProjects,
[ProjectStatus] = "Active"
)
)
This formula will count the rows in UniqueProjects where the ProjectStatus is "Active".

Closed Projects:
Similarly, create a measure to count closed projects:
Closed Projects =
COUNTROWS(
FILTER(
UniqueProjects,
[ProjectStatus] = "Closed"
)
)
On-Hold Projects:
Finally, create a measure to count the on-hold projects:
Onhold Projects =
COUNTROWS(
FILTER(
UniqueProjects,
[ProjectStatus] = "On-Hold"
)
)
Visualization:
Now, when you create a matrix or a table visualization in Power BI:
Drag ProjectType to Rows.
Drag the three measures Active Projects, Closed Projects, and Onhold Projects to Values.
This will show the counts in the desired format.

Remember, DAX context plays an important role. These measures will respect any filters or slicers you have on your report. So if you apply a date slicer or filter, the measures will only count the projects within that date range.

View solution in original post

3 REPLIES 3
technolog
Super User
Super User

To get the desired result, you can use DAX to create measures that perform these calculations. Here are the steps and DAX measures you can create.

Unique Projects:
Firstly, create a table that captures unique projects over the entire duration:
UniqueProjects = SUMMARIZE('TableName', 'TableName'[ProjectID], LASTNONBLANK('TableName'[Date], 1), 'TableName'[ProjectStatus], 'TableName'[ProjectType])
This formula creates a new table, UniqueProjects, which summarizes the original table by ProjectID, and captures the latest status and type for each unique project.

Active Projects:
Now, create a measure to count active projects:
Active Projects =
COUNTROWS(
FILTER(
UniqueProjects,
[ProjectStatus] = "Active"
)
)
This formula will count the rows in UniqueProjects where the ProjectStatus is "Active".

Closed Projects:
Similarly, create a measure to count closed projects:
Closed Projects =
COUNTROWS(
FILTER(
UniqueProjects,
[ProjectStatus] = "Closed"
)
)
On-Hold Projects:
Finally, create a measure to count the on-hold projects:
Onhold Projects =
COUNTROWS(
FILTER(
UniqueProjects,
[ProjectStatus] = "On-Hold"
)
)
Visualization:
Now, when you create a matrix or a table visualization in Power BI:
Drag ProjectType to Rows.
Drag the three measures Active Projects, Closed Projects, and Onhold Projects to Values.
This will show the counts in the desired format.

Remember, DAX context plays an important role. These measures will respect any filters or slicers you have on your report. So if you apply a date slicer or filter, the measures will only count the projects within that date range.

skasper
Responsive Resident
Responsive Resident

Hi,

 

you can get this view without any calculations, by using a matrix visual with 'ProjectType' as row elements and 'ProjectStatus' as column element and of course using 'Date' as a filter.

 

If you still need or want to calculate it manually, you could do it by defining a measure for each:

 

Active Project A = 
CALCULATE(
	COUNTA(Table1[ProjectID]);
	FILTER(Table1;
		Table1[ProjectStatus ] = "Active" &&
		Table1[ProjectType] = "GroupeA"
	)
)

Note that this is not a very efficient solution, as you would have to define one measure per status/project combination.

 

A better approach would be to just count the ProjectID and use filters. In that way you would have a single measure only:

 

Count Projects = COUNTA(Table1[ProjectID])

Hope this helps.

 

 

Best - Sascha
Please always mark accepted solutions. It helps others with similar questions or problems. Thank you.

Thank you for the feedback. 

My challenge is that if a project has more than one 'Status' in the time period. The project will be counted for both Status'. However, I only want to count the most resent 'ProjectStatus' for each Project.

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.

Top Solution Authors