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
ltang6
Frequent Visitor

DAX - How to calculate maximum of daily unique count within current month using measure

Hi all,

 

I want to use DAX to calculate a measure based on Powerbi Dataset. Since i need to publish it, i cannot include any calculated columns or tables.

 

The objective is to calculate the maximum unique user utilization in the current month.

The methodology is:

1. Restrict to latest month using 'Month' column, and to correct tenant. I only want 'test1'.

2. Count the unique number of user for each date -> daily utilization.

3. Return the maximum daily utilization of this latest month.

 

The result of this measure will be displayed in a 'Card' visualization.

I would also want to apply extra filter from Visualization filter to restrict user department.

For the data listed below, by applying the department filter to be only 'Group 1', i would expect the correct output to be 3.

'Group 1' cannot be hardcoded like 'test1' because it is subject to change.

 

My sample data are like this:

Table 1 contains a list of user activity.

User

Date

Month

Tenant

a@gmail.com

1-Aug-23

1-Aug-23

test1

b@gmail.com

1-Aug-23

1-Aug-23

test1

a@gmail.com

1-Aug-23

1-Aug-23

test1

c@gmail.com

1-Aug-23

1-Aug-23

test1

d@gmail.com

1-Aug-23

1-Aug-23

test1

c@gmail.com

2-Aug-23

1-Aug-23

test1

d@gmail.com

2-Aug-23

1-Aug-23

test2

 

Table 2 contains the details information on each user.

User

Department

a@gmail.com

Group 1

b@gmail.com

Group 1

c@gmail.com

Group 2

d@gmail.com

Group 1

The relationship between the two tables are already build by link the two User columns.

1 ACCEPTED SOLUTION
davidwyt
New Member

below is how to calculate max distinct count of users, and you can add filters to set current month and tenant

 

Calculate(
    MaxX(
        Values('Table1'[Date]),
        Calculate(
             DISTINCTCOUNT ('Table1'[user])
        )
)

View solution in original post

4 REPLIES 4
davidwyt
New Member

below is how to calculate max distinct count of users, and you can add filters to set current month and tenant

 

Calculate(
    MaxX(
        Values('Table1'[Date]),
        Calculate(
             DISTINCTCOUNT ('Table1'[user])
        )
)

Yes simplicity is best, it is working! i keep thinking about the outside filter will not be able to apply, but IT WORKS!

ltang6
Frequent Visitor

Hello Binbin,

 

Thank you so much for your reply.

I think what you suggest is exactly what i need. It's only that the actual database is quite large.

Up on trying the above DAX, i have got the error that the query size is too large.

Not sure if there's a way to solve this.

ltang6_0-1691546026301.png

 

Anonymous
Not applicable

Hi @ltang6 ,

Please try to create a measure with below dax formula:

Measure =
VAR cur_dpt =
    SELECTEDVALUE ( 'Table 2'[Department] )
VAR tmp =
    CALCULATETABLE (
        VALUES ( 'Table 2'[User] ),
        FILTER ( ALL ( 'Table 2' ), [Department] = cur_dpt )
    )
VAR tmp1 =
    FILTER ( ALL ( 'Table 1' ), [User] IN tmp )
VAR tmp2 =
    SUMMARIZE ( tmp1, [Month], "Cnt", DISTINCTCOUNT ( 'Table 1'[User] ) )
RETURN
    SUMX ( tmp2, [Cnt] )

Add a card visual with measure:

Animation19.gif

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.