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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.