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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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