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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
SteveIves
Frequent Visitor

Calculate a new column using data from the same row

I have a table in Power BI with the following 3 columns:

 

Incident Number, Date Opened, Date Closed

It has about 1,000 rows, covering 3 years.

 

I want to create a graph showing how many incidents were open on each of the dates in the table. To that end, I have created a date table with all dates covered by the Incident table:

 

Dates = CALENDAR(MIN('Incidents'[Date Opened]), MAX('Incidents'[Date Opened]))

 

For every date, I want to create a count of how many incidents were open (so either a close date after that date or no close date (incident is still open).

 

So what I need is to do is something like :

 

Dates[Open Count] = COUNTROWS(FILTER('Incidents', ('Incidents'[Date Opened] < 'Dates[Date]) AND ('Incidents[Date Closed] > 'Dates[Date] OR  'Incidents[Date Closed] = BLANK() ))
 (I know that's not valid DAX).
 
So for every row in my 'Dates' table, get the number of Incidents that were open on that date (i.e. the open date is before the date we are looking at in the 'Dates' table and closed date is later than that date or blank).
 
This is so we can see the trend in the number of open incidents. 
 
Thanks, Steve
 

 

3 REPLIES 3
lbendlin
Super User
Super User

add the table name, slap a MAX() around it or use variables.  The exact syntax depends on your scenario.

SteveIves
Frequent Visitor

Thanks for that. 

 

I've not managed to try it yet as I'm getting the error:

SteveIves_4-1683189585198.png

 

It's also showing that the [Date] field isn't found, which I worked out is due to this error:

SteveIves_3-1683188974941.png

 

Did that expression work for you?

lbendlin
Super User
Super User

Nearly there.

 

[Open Count] = CALCULATE(COUNTROWS('Incidents'),'Incidents'[Date Opened] < [Date]),COALESCE('Incidents[Date Closed],[Date]) > [Date])

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.