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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
pplanch
Regular Visitor

Aggregating / counting records with DAX using conditions

I have a table showing below.

 

pplanch_0-1711527590783.png

 

What I need to do through DAX (measure ... I don't have access to make changes to the underlying data source) is produce a column with a total count for each name - "Naam" - where "Reden" equals "Hoofdperiode". So for every record for "Jan" it should show 4 except where "Reden" shows "Vervolg", for every record for "Mieke" it should show 2 except where "Reden" shows "Vervolg".

 

I'm not finding the right DAX functions / formula to use ... anybody has some suggestions?

 

Thanks

1 ACCEPTED SOLUTION

I did it for you in Power Query in post above, but if you want to create this in DAX here you go:

 

dufoq3_0-1711531017145.png

Hoofdperiode Count = 
CALCULATE(
    COUNTROWS(tblSicknessData),
    FILTER(
        ALLEXCEPT(tblSicknessData, tblSicknessData[Naam]),
        tblSicknessData[Reden] = "Hoofdperiode"
    )
)

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

6 REPLIES 6
dufoq3
Super User
Super User

Hi @pplanch,

 

Power Query version:

Result

dufoq3_0-1711528831987.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMU9JRMgRiIyD2yM9PSylILcrMT0lVitVBlw5LLSrLz0nHIkNAI6nSvpmp2amkKEB2GX7NsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Naam = _t, Start = _t, Einde = _t, Reden = _t]),
    GroupedRows = Table.Group(Source, {"Naam"}, {{"All", each _, type table}, {"Hoofdperiode Count", each Table.RowCount(Table.SelectRows(_, (x)=> x[Reden] = "Hoofdperiode")), Int16.Type}}),
    ExpandedAll = Table.ExpandTableColumn(GroupedRows, "All", {"Start", "Einde", "Reden"}, {"Start", "Einde", "Reden"})
in
    ExpandedAll

 

 

If you want Dax Measure, create new calculated column wit if:

 

Hoofperiode Count = IF([Reden] = "Hoofdperiode", 1, 0)

 

And then just create sum measure for [Hoofperiode Count] column. Put [Naam] into rows.

 

or create direct measure:

Hoofperiode Count = 
CALCULATE(
    COUNTROWS(YourTable),
    KEEPFILTERS(YourTable[Reden] = "Hoofdperiode")
)

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

@dufoq3, thanks for your suggestion. First step ... no problem. When creating the measure for the sum, the result seems to be the same as the one for the calculated column. Anything I'm dowing wrong? I tried with SUM but that didn't allow for putting any argument into Rows, screenshot below shows an attempt with SUMX

(these are my first steps in DAX)

 

pplanch_0-1711529729700.png

 

I'm not sure what do you want to achieve.

 

Create this measure

Hoofperiode Count = 
CALCULATE(
    COUNTROWS(tblSicknessData),
    KEEPFILTERS(tblSicknessData[Reden] = "Hoofdperiode")
)

 

Put Naam into matrix rows and use this measure. It will show you count of all "Hoofdperiode" for every Naam.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

@dufoq3 Not sure how to "put Naam into matrix rows", as I am not yet familiar with the ins and outs of DAX. What I try to achieve, is showing in screenshot below (from Excel "simulation")

pplanch_0-1711530351698.png

 

I did it for you in Power Query in post above, but if you want to create this in DAX here you go:

 

dufoq3_0-1711531017145.png

Hoofdperiode Count = 
CALCULATE(
    COUNTROWS(tblSicknessData),
    FILTER(
        ALLEXCEPT(tblSicknessData, tblSicknessData[Naam]),
        tblSicknessData[Reden] = "Hoofdperiode"
    )
)

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

@dufoq3 Thanks alot. Since I don't have access to the data model, DAX was the only way ... solution appears to work like a charm 🙂

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Kudoed Authors