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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
he2mpo
Frequent Visitor

Counting rows with variance from same table

Hello all

 

I have two tables one for tasks and the second for projects. Each project has many tasks. The tasks table shown below

it has fields as id code, project id, start date and finish date.

he2mpo_0-1686913306730.png

 

The second table is a simple one having project id and project name

he2mpo_1-1686913392199.png

It is important to note that the connection between the tasks is the task code as the ids are not the same between different project

 

I have created two slicers for users to select the current project and the baseline project. Then created a set of measures to calculate the start and finish dates based on the selected values in both slicers.

he2mpo_3-1686913834491.png

 

 

Now what I am trying to achieve is to count the number of activities where the variance is less than 0.

I tried creating a virtual table that will have the start date from the baseline and the start date from the current forcast and then used COUNTX with filter. Unfortunatley this did not work as it returned the total count of activites.

 

 

 

cnt = 
var comb = 
ADDCOLUMNS(TASK, 
    "task_code", CALCULATE(DISTINCT(TASK[task code]), FILTER(TASK, TASK[proj] = LASTNONBLANK('Current'[proj id],1))) ,
    "blStart", CALCULATE(Min(TASK[Start]), filter(TASK, TASK[proj] = LASTNONBLANK(Baselines[proj id],1))),
    "curStart", CALCULATE(min(TASK[Start]), FILTER(TASK, TASK[proj] = LASTNONBLANK('Current'[proj id],1)))
)
RETURN
COUNTX(Filter(comb, ([blStart] - [curStart])*1.0 < 0 ), [task code])

 

 

 

I appreciate if you could help in this issue. 

The link to pbix and data file is here

Comparison Example

 

Many thanks

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

2 REPLIES 2
lbendlin
Super User
Super User

lbendlin_0-1687047598139.png

 

This is a super elegant solution. Thank you!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.