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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
WOLFIE
Helper I
Helper I

SUM values from table A for groups in table B

Hi all.

 

Is there any other way to write this measure please? The measure works but performance is very poor. 

TABLE 1:

Count of employeesAgeGenderGroup 1Group 2Group 3Group 4Group 5Group 6Group 7Group 8Group 9Group 10
120FTrueFalseFalseFalseFalseTrueFalseFalseFalseFalse
120FTrueTrueTrueTrueFalseTrueTrueTrueTrueFalse
222MTrueTrueFalseFalseFalseTrueTrueFalseFalseFalse
536MTrueFalseTrueFalseFalseTrueFalseTrueFalseFalse
657FFalseTrueTrueFalseFalseFalseTrueTrueFalseFalse
454MTrueFalseTrueFalseFalseTrueFalseTrueFalseFalse
752MTrueFalseTrueFalseFalseTrueFalseTrueFalseFalse
832FFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
925FTrueTrueTrueFalseFalseTrueTrueTrueFalseFalse
432MTrueTrueFalseFalseFalseTrueTrueFalseFalseFalse
825MTrueFalseTrueFalseFalseTrueFalseTrueFalseFalse
154FFalseTrueTrueFalseFalseFalseTrueTrueFalseFalse
133MFalseTrueTrueFalseFalseFalseTrueTrueFalseFalse
121FTrueTrueFalseFalseFalseTrueTrueFalseFalseFalse

 

TABLE 2:

Groups
Group 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10

 

MEASURE :

Employee Count By Group =
var List = VALUES('Groups'[Groups])
RETURN
SUMX(FILTER('Employees',
("Group 1" IN List && 'Employees'[Group 1]) ||
("Group 2" IN List && 'Employees'[Group 2]) ||
("Group 3" IN List && 'Employees'[Group 3]) ||
("Group 4" IN List && 'Employees'[Group 4]) ||
("Group 5" IN List && 'Employees'[Group 5]) ||
("Group 6" IN List && 'Employees'[Group 6]) ||
("Group 7" IN List && 'Employees'[Group 7]) ||
("Group 8" IN List && 'Employees'[Group 8]) ||
("Group 9" IN List && 'Employees'[Group 9]) ||
("Group 10" IN List && 'Employees'[Group 10])
),[Count of employees]) + 0
 
6 REPLIES 6
daxer-almighty
Solution Sage
Solution Sage

@WOLFIE, no amount of DAX can make a BAD MODEL fast.

WOLFIE
Helper I
Helper I

@edhans @Thank you very much for your reply. The problem is that I cannot change the data model. Table with true-false has 30 million of rows after aggregation. The data is loading in very fast but I need to change the measure to make it faster. There is no relationship between these 2 tables.

@WOLFIE - Not sure I understand why you cannot change the table before it comes in. If someone is doing that for you upstream, talk to them and have that table unpivoted after the aggregation. My measure would work in milliseconds on 30M rows. DAX is designed for data to be in one column like I've done. I mean, literally designed as it is based on the SQL Server Analysis Services Tabular model. You are using a flat denormalized model, and that will get slower and slower over time. And your DAX is way WAY too complex because the model is badly designed as is.

You can read more here, and SQLBI has a book and course on modeling.

What is normalizing data? See the Normalizing an example table section of this paper



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
daxer-almighty
Solution Sage
Solution Sage

Do what @edhans says. Fact tables in Power BI should be long but narrow. Dimensions should be wide but short. Stick to this religiously.

Thanks @daxer-almighty I understand why and if I didn't work with that big data I would definitely stick to it. My initial model had 3 tables and each around 70 million of rows ", therefore I had to aggregate the data because it was struggling to refresh it and impossible to load all of that data in. Only this one measure is slowing it down.

edhans
Super User
Super User

If I understand your requirement @WOLFIE this measure works, and will be super fast.

 

 

Employee Count = 
COALESCE(
    SUMX(
        FILTER(
            'Employees Revised',
            'Employees Revised'[Value] = TRUE()
        ),
        'Employees Revised'[Count of employees]
    ),
    0
)

 

 

However, you have to remodel your data. Your data isn't normalized. I normalized it. I unpivoted the Group* columns in your employee table so it look like this:

edhans_0-1608146026663.png

Then modeled it like this:

edhans_1-1608146056475.png

and it returns this:

edhans_3-1608147191825.png

 

You can see my full PBIX here. Go to Transform Data and look at the Unpivot operation in Power Query to see how I did the table modification. It is the Employee Revised table.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.