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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
JoelTib
Frequent Visitor

DAX - Count number of items

Hello all,

 

I am after some help with a DAX measure.

 

I have a dataset that resembles the following:  

 

DateClientAssigned ToWeek Beginning
13-AugABill7-Aug
13-AugBBob7-Aug
13-AugCBen7-Aug
13-AugDBarry7-Aug
13-AugEBecky7-Aug
13-AugFBill7-Aug
13-AugGBill7-Aug
13-AugHBob7-Aug
13-AugIBen7-Aug
6-AugABill31-Jul
6-AugBBob31-Jul
6-AugCBen31-Jul
6-AugDBarry31-Jul
6-AugEBecky31-Jul
6-AugFCarl31-Jul
6-AugGBill31-Jul
6-AugHBill31-Jul
6-AugIBill31-Jul
30-JulABill24-Jul
30-JulBBob24-Jul
30-JulCBen24-Jul
30-JulDStan24-Jul
30-JulEMatthew24-Jul
30-JulFEric24-Jul
30-JulGNath24-Jul
30-JulHCharles24-Jul
17-JulACharles17-Jul
17-JulCNath17-Jul
17-JulDEric17-Jul
17-JulEBill17-Jul
17-JulGBob17-Jul

 

I have been trying to write a DAX measure that will work under two situations. 

 

Firstly, I would like it to filter the 'Week Beginning' column for rows containing data from the current week (i.e., with respect to TODAY()), or the most recent week in the table, and then give me a count for the number of 'Clients' each 'Assigned to' name has.  

 

For example, from the data above I would like the following output (i.e., this is filtering for 'Assigned To' names that have the most recent 'Week Beginning' date of the 7th-Aug): 

 

Assigned ToClient Count
Bill3
Bob2
Ben2
Barry1
Becky1

 

Secondly, if however, I have selected a particular week beginning date from another visual on my Power BI dashboard, I would like the output to show me the list of 'Assigned to' names, and their 'Client Count' for the particular week I have selected on said visual.   

 

Is this possible?  I am still very much learning the intricacies of DAX so any help would be most appreciated.  

 

Kind regards,

Joel

 

 

 

 

 

 

 

 

 

2 ACCEPTED SOLUTIONS
v-rzhou-msft
Community Support
Community Support

Hi @JoelTib ,

 

I suggest you to create an unrelated table to help our calculation.

DimWeek Beginning = 
VALUES('Table'[Week Beginning])

Measure:

Count of Client =
VAR _SELECTVALUE =
    SELECTEDVALUE ( 'DimWeek Beginning'[Week Beginning] )
VAR _RECENTWEEKBEGING =
    MAXX (
        FILTER ( ALL ( 'Table' ), 'Table'[Week Beginning] <= TODAY () ),
        'Table'[Week Beginning]
    )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Client] ),
        FILTER (
            'Table',
            'Table'[Week Beginning]
                = IF (
                    ISFILTERED ( 'DimWeek Beginning'[Week Beginning] ),
                    _SELECTVALUE,
                    _RECENTWEEKBEGING
                )
        )
    )

Result is as below.

vrzhoumsft_0-1692169979897.pngvrzhoumsft_1-1692169987007.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

Dear Rico,

 

Thank you so much for your help.  This solution is great.  Does the job perfectly.  Many, many thanks!

 

Cheers,

Joel

View solution in original post

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @JoelTib ,

 

I suggest you to create an unrelated table to help our calculation.

DimWeek Beginning = 
VALUES('Table'[Week Beginning])

Measure:

Count of Client =
VAR _SELECTVALUE =
    SELECTEDVALUE ( 'DimWeek Beginning'[Week Beginning] )
VAR _RECENTWEEKBEGING =
    MAXX (
        FILTER ( ALL ( 'Table' ), 'Table'[Week Beginning] <= TODAY () ),
        'Table'[Week Beginning]
    )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Client] ),
        FILTER (
            'Table',
            'Table'[Week Beginning]
                = IF (
                    ISFILTERED ( 'DimWeek Beginning'[Week Beginning] ),
                    _SELECTVALUE,
                    _RECENTWEEKBEGING
                )
        )
    )

Result is as below.

vrzhoumsft_0-1692169979897.pngvrzhoumsft_1-1692169987007.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Dear Rico,

 

Thank you so much for your help.  This solution is great.  Does the job perfectly.  Many, many thanks!

 

Cheers,

Joel

lbendlin
Super User
Super User

DAX is not always necessary. Consider a graphical solution to your question based on a Matrix visual

 

lbendlin_0-1692145656534.png

 

Dear @lbendlin,

 

Thank you very much for your help.  Much appreciated.

 

Cheers,

Joel

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.