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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
DotU
Frequent Visitor

Count rows based on two date conditions being met across two columns

Hi everyone, I have a fact table which has two date columns: risk raised date and risk closed date. I need to build a graph which shows (sample graph image included below):
A - how many risks were open in each month
B - total risks identified (cumlative total across the months)
C - new risks added each month (risk raised date = current month) -- acheived
D - risks closed each month (risk closed date = current month) -- acheived

To complete C & D, my data model has a date table and my Fact Table called "CRITER_Risk Data". This is what I did:
 - Creating two inactive relationships (date -> raised date) and ( date -> closed date)
 - using the date table on x-axis and creating two measures as using "userealtionship" 

I'm trying to work on "A - how many risks were open in each month"

To get the total open risks at any date, we need two (both) conditions to be met:

A, raised date has to be on or before the selected date

B, closed date should be blank or after the selected date.

 

I am able to partially meet requirement A with this measure:

CALCULATE(COUNTROWS('CRITER_Risk Data'), 'CRITER_Risk Data'[Risk Raised Date] = MAX('Date'[Date]))

When plotted against the date table, this gives me count of risks raised on each date.

I tried to update this to say <= but that breaks the measure - not sure why.

What I need:

DotU_0-1674714792717.png

This is where I am so far:

DotU_1-1674714886806.png

 

Many thanks!!



1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

10 REPLIES 10
Sams11
Frequent Visitor

Hi Ashish, Could you please share this file?

Hi,

I do not have that file.  Share data in a format that can be pasted in an MS Excel file, explain the question and show the expected result.


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

Hi,

Share some data in a format that can be pasted in an MS Excel file and show the expected result clearly in a Table format.


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

Hi Ashish,

Thanks for the reply. I've shared sample data and expected output above.

Below is the expected output for requirement B which is mainly a cumulative total:

Expected output in table format for "B":
MonthYearTotal Identified
Jan20213
Feb20217
Mar20219
Apr202110
May202110
Jun202110

SAMPLE FACT DATA:  
Risk NoRisk StatusRaised DateClosed Date
A0001Open1/1/2021 
A0002Open1/1/2021 
A0003Closed1/1/20213/15/2021
A0004Open2/1/2021 
A0005Open2/1/2021 
A0006Closed2/1/20214/12/2021
A0007Open2/1/2021 
A0008Open3/1/2021 
A0009Closed3/1/20216/2/2021
A0010Open4/1/2021

 

   

 

   

 

 

Expected output in table format for "A": 
MonthYearTotal OpenNotes (fyi)
Jan20213three raised in jan, all open
Feb20217three raised in jan, 4 raised in feb, all open by end of feb
Mar20218three raised in jan, 4 raised in feb, 2 raised in march = 9. Of these, one was closed in march so total open are 8
Apr20218compared to March, one more added and one closed so still 8 open
May20218no change
Jun20217one more closed

 

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

Hi @Ashish_Mathur ,

This was fantastic. Thank you very mcuh.
It was brilliant to think of finding total raised - total closed = net open. 
I was complcating the whole process with trying to use opened before and closed after for filters... still surprised why i didn'tt hink of it this way!

Also, it was good learning for me how u used the risk status = closed as a filter as it automatically got rid of the blank dates (cause again i would have tried to build a filter date no blank.. whereas it is easier to just used the status column as the filter)

I needed running totals instead of YTD, I was able to modify the formulas you provided with the help of this link: https://www.sqlbi.com/articles/computing-running-totals-in-dax/

Once again, really appreciate it! 

Regards,
Aisha

You are welcome.


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

Hi, 

 

I believe I have a very similar problem as the original poster. Unfortunately I am unable to download the .pbix files attached to the solution. Could you kindly please share the process you used to arrive to your solution (can be a general outline/guidance) for users that cannot download the file?

 

Thank you,

 

Elizabeth

Hi Elizabeth,

There are the 4 measures I used to bring the whole thing together - with the help of Ashish, of course. The measures rely on two inactive relationships:

Fact Table called "CRITER_Risk Data" which has the two date columns.

Date Table with Dates
 Created two inactive relationships (date -> raised date) and ( date -> closed date)


New Risks =
CALCULATE(
    COUNTROWS('CRITER_Risk Data'),
    USERELATIONSHIP('CRITER_Risk Data'[Risk Raised Date], 'Date'[Date])
)
 
Closed Risks =
CALCULATE(
    COUNTROWS('CRITER_Risk Data'),
    'CRITER_Risk Data'[Risk Status New] = "Closed",
    USERELATIONSHIP('CRITER_Risk Data'[Risk Closure Date New], 'Date'[Date]))
 
Total Open =
VAR _MaxDate = MAX('Date'[Date])

VAR _RaisedRT =
CALCULATE(
    [New Risks],
    'Date'[Date] <= _MaxDate,
    ALL('Date'))

VAR _ClosedRT =
CALCULATE(
    [Closed Risks],
    'Date'[Date] <= _MaxDate,
    ALL('Date'))

Return
_RaisedRT - _ClosedRT
 
Raised RT =
VAR _MaxDate = MAX('Date'[Date])

VAR _RaisedRT =
CALCULATE(
    [New Risks],
    'Date'[Date] <= _MaxDate,
    ALL('Date'))

RETURN
_RaisedRT

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.