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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ixtilion
Regular Visitor

Sum values of an employee only when he doesnt have X value in the table for a range of dates

Hello,

I've been trying to figure this one out but its proving to be a bit tough...

What I need to do in DAX is a sum of the "Value" column only when the CHECK1 and CHECK2 columns for that employee are set to 0 in all the other rows for the selected Date range.

 

This is an example dataset:

EMPLOYEE IDVALUECHECKCHECK2DATE
110001/01/2019
110002/01/2019
110003/01/2019
110004/01/2019
110005/01/2019
110006/01/2019
211003/01/2019
210004/01/2019
210005/01/2019
210006/01/2019
310001/06/2019
310102/06/2019

 

  • In this case, when selecting a date range from day 1 to day 6, the measure should just return 6 (the sum of all the values for employee 1). Employees 2 and 3 wouldnt be accounted for as they have one of their rows set as 1 in the check columns.
  • If I selected a date range from day 5 to day 6, it should return 4 (2 values from employee1, and 2 values from employee2)

 

Thanks,

if I can provide any more info or explain the issue any further I'd be glad to do so

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi @ixtilion,

 

I got this code to work on your sample data

Measure =
VAR _t =
    ADDCOLUMNS (
        VALUES ( 'Table'[EMPLOYEE ID] );
        "c1"; CALCULATE ( SUM ( 'Table'[CHECK] ) );
        "c2"; CALCULATE ( SUM ( 'Table'[CHECK2] ) )
    )
VAR _tt =
    CALCULATETABLE (
        VALUES ( 'Table'[EMPLOYEE ID] );
        FILTER ( 'Table'; ( 'Table'[EMPLOYEE ID]; 0; 0 ) IN _t )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[VALUE] );
        FILTER ( 'Table'; ( 'Table'[EMPLOYEE ID] ) IN _tt )
    )

Regards,

S

View solution in original post

2 REPLIES 2
sturlaws
Resident Rockstar
Resident Rockstar

Hi @ixtilion,

 

I got this code to work on your sample data

Measure =
VAR _t =
    ADDCOLUMNS (
        VALUES ( 'Table'[EMPLOYEE ID] );
        "c1"; CALCULATE ( SUM ( 'Table'[CHECK] ) );
        "c2"; CALCULATE ( SUM ( 'Table'[CHECK2] ) )
    )
VAR _tt =
    CALCULATETABLE (
        VALUES ( 'Table'[EMPLOYEE ID] );
        FILTER ( 'Table'; ( 'Table'[EMPLOYEE ID]; 0; 0 ) IN _t )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[VALUE] );
        FILTER ( 'Table'; ( 'Table'[EMPLOYEE ID] ) IN _tt )
    )

Regards,

S

@sturlaws thanks a lot, it works perfectly and I learned something about using variables and tables in DAX expressions!

 

Im going to try it out in a real enviroment with a lot of rows and see how it performs, thanks for the insight 🙂

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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