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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mariella2
Helper I
Helper I

Help to convert a calculated column into a measure that counts the overdue tasks overtime

Hi all, I need your help in creating a measure that shows the same results of the calculated column.

The calculated column is used on a line chart to count the overdue tasks at the end of each month of the year. To make the calculation, I have created a second calendar table (Calendar EOM) disconnected from the main calendar table and the fact table, where all the relantionship are ( Date Opened has an active relantionship with calendar date, teh other inactive with calendar date are date closed, expected date, and date validated). 

 

The Expected date is the Due date and it is a calculated column based on the category and the number of days allowed to complete the task.

My issue is that I can't use the Overdue (in the screenshot above - Non Compliant) from the Calendar EOM) because I can't use the drillthrough function from the line chart even if I create the relantionship between the Calendar EOM and the fact table. The results are not correct. For clarity, I will copy the code behind the Calendar EOM, so that you can have a better understanding of the calculations behind.

 

Calendar EOM = FILTER (
    CALENDAR ( MIN ( 'Fact'[Date Opened] ), TODAY() ),
    [Date] = EOMONTH ( [Date], 0 )
)

 

Vulnerabilities Count =
CALCULATE(
    COUNTROWS('Fact'),
    FILTER(
        ALL('Fact'),
        MONTH('Fact'[Date Closed]) = MONTH('Calendar EOM'[Date])
            &&  YEAR('Fact'[Date Closed]) = YEAR('Calendar EOM'[Date])
            && 'Fact'[Date Closed] > 'Fact'[Expected Completion Date ]
    )
)
 
Vulnerabilities Count Blank =
CALCULATE(
    COUNTROWS('Fact'),
    FILTER(
        ALL('Fact'),
        ISBLANK('Fact'[Date Closed])
         && 'Calendar EOM'[Date] > 'Fact'[Expected Completion Date ]
    ))

Vulnerabilities Count BlankX =
CALCULATE(
    COUNTROWS('Fact'),
    FILTER(
        ALL('Fact'),
        'Fact'[Date Closed] >'Calendar EOM'[Date]
         && 'Calendar EOM'[Date] > 'Fact'[Expected Completion Date ]
    ))

Overdue Non Compliant = 'Calendar EOM'[Vulnerabilities Count Blank]+'Calendar EOM'[Vulnerabilities Count BlankX]+'Calendar EOM'[Vulnerabilities Count]

 

Now the count is correct, I just want to reproduce it as a measure so that I can use it to drillthrough on a table visual.

So far the measure I got working is the following, but some totals are not the same, which is wrong:

 

Overdue  = var dateToExamine = MAX('Calendar'[Date]) var row_count = COUNTROWS(FILTER(ALL('Fact'), ('Fact'[Date Closed]>dateToExamine || ISBLANK('Fact'[Date Closed]))&& 'Fact'[Expected Completion Date ]<dateToExamine))
RETURN
IF(ISBLANK(row_count),0,row_count)

 

What am I missing? Any help is much appreaciated.

Sample data below

 

 

1 ACCEPTED SOLUTION
sjoerdvn
Super User
Super User

I would think something more like below, but it needs additional logic to not count everything as overdue with future expected completion dates.

Overdue  =
CALCULATE(COUNTROWS('Fact')
	, USERELATIONSHIP('Fact'[Expected Completion Date], 'Calendar'[Date])
	,'Fact'[Date Closed] > 'Fact'[Expected Completion Date ])
+ CALCULATE(COUNTROWS('Fact')
	,USERELATIONSHIP('Fact'[Expected Completion Date], 'Calendar'[Date])
	,ISBLANK('Fact'[Date Closed])

 And you do not need that extra date table... 

View solution in original post

3 REPLIES 3
sjoerdvn
Super User
Super User

I would think something more like below, but it needs additional logic to not count everything as overdue with future expected completion dates.

Overdue  =
CALCULATE(COUNTROWS('Fact')
	, USERELATIONSHIP('Fact'[Expected Completion Date], 'Calendar'[Date])
	,'Fact'[Date Closed] > 'Fact'[Expected Completion Date ])
+ CALCULATE(COUNTROWS('Fact')
	,USERELATIONSHIP('Fact'[Expected Completion Date], 'Calendar'[Date])
	,ISBLANK('Fact'[Date Closed])

 And you do not need that extra date table... 

I tried the measue as is  above, and I'm not having the expected results. Anyway I will try to add more logic as you suggested.

 

Any other suggestion, please?

 

to be able to help I would need sample data and the exact expected numbers from that sample data.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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