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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Monepieveloce
Frequent Visitor

Count of users at each status at a specific date

Hello All! 
I have a table with columns username, current status and update date. In this table all the changes of status are recorded.
I need to calculate the count of users at each status and filter it by month, so when then month filter is applied the calculation should show the outcome at the end of that month.
Sample table:

UsernameCurrent StatusUpdate Date
AAA11/May/24
BBB11/May/24
CCC21/May/24
DDD31/May/24
EEE41/May/24
AAA21/Jun/24
FFF11/Jun/24
BBB21/Jun/24
CCC21/Jun/24
AAA11/Jul/24
GGG21/Jul/24
AAA41/Aug/24

Sample expected result:

May filter applied
Status# Count
12
21
31
41
June filter applied
Status# Count
11
23
31
41
July filter applied
Status# Count
12
23
31
41
August filter applied
Status# Count
11
23
31
42


Anyone can help? 

Thank you!

2 ACCEPTED SOLUTIONS

@Monepieveloce 

1. Create a separate table for Dates, in my case i named it DateSampleTable, with this code:

DateSampleTable = DISTINCT(SampleTable[Update Date])
2. Create the measure:
CountByUsernameStatus =
VAR VirtualTable =
    CALCULATETABLE(SUMMARIZE(FILTER('SampleTable', SampleTable[Update Date] <= SELECTEDVALUE(DateSampleTable[Update Date])), SampleTable[Username], "Date", MAX(SampleTable[Update Date]), "STATUS", MAX(SampleTable[Current Status])))

RETURN
    COUNTROWS(VirtualTable)
Try it and let me know.
 
BBF

View solution in original post

v-zhouwen-msft
Community Support
Community Support

Hi all,thanks for the quick reply, I'll add more.

Hi @Monepieveloce ,

Please follow these steps:

1.Deleting a relationship between tables.

vzhouwenmsft_0-1720689808375.png

2.Use the following DAX expression to create a table

Table = VALUES(UsersTable[Current Status])

3.Use the following DAX expression to create a measure

Measure = 
VAR _dateForSlicer = MIN('DateTable'[Date].[Date])
VAR _status = SELECTEDVALUE('Table'[Current Status])
VAR _table = SUMMARIZE(FILTER('UsersTable',[Update Date] <= _dateForSlicer),[Username],"Update Date",MAX('UsersTable'[Update Date]))
VAR _table2 = ADDCOLUMNS(_table,"Current Status",LOOKUPVALUE(UsersTable[Current Status],UsersTable[Username],[Username],UsersTable[Update Date],[Update Date]))
VAR _result = COUNTROWS(FILTER(_table2,[Current Status] = _status))
RETURN _result

4.Final output

vzhouwenmsft_1-1720689943055.png

vzhouwenmsft_2-1720689953300.png

Best Regards,
Wenbin 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

12 REPLIES 12
v-zhouwen-msft
Community Support
Community Support

Hi all,thanks for the quick reply, I'll add more.

Hi @Monepieveloce ,

Please follow these steps:

1.Deleting a relationship between tables.

vzhouwenmsft_0-1720689808375.png

2.Use the following DAX expression to create a table

Table = VALUES(UsersTable[Current Status])

3.Use the following DAX expression to create a measure

Measure = 
VAR _dateForSlicer = MIN('DateTable'[Date].[Date])
VAR _status = SELECTEDVALUE('Table'[Current Status])
VAR _table = SUMMARIZE(FILTER('UsersTable',[Update Date] <= _dateForSlicer),[Username],"Update Date",MAX('UsersTable'[Update Date]))
VAR _table2 = ADDCOLUMNS(_table,"Current Status",LOOKUPVALUE(UsersTable[Current Status],UsersTable[Username],[Username],UsersTable[Update Date],[Update Date]))
VAR _result = COUNTROWS(FILTER(_table2,[Current Status] = _status))
RETURN _result

4.Final output

vzhouwenmsft_1-1720689943055.png

vzhouwenmsft_2-1720689953300.png

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

Monepieveloce
Frequent Visitor

Anyone has an idea to solve this please? Thanks!

This reply is informational. Please follow the decorum of the Community Forum when asking a question.

Please share your work-in-progress Power BI Desktop file (with sensitive information removed) and any source files in Excel format that fully address your issue or question in a usable format (not as a screenshot). You can upload these files to a cloud storage service such as OneDrive, Google Drive, Dropbox, or to a Github repository, and then provide the file's URL.

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied.

@foodd Thank you for the guidelines! 
I have shared the sample file here: https://we.tl/t-YcGOXa0Qm6 
I have added in the file how I would like to visualize the data (column chart + month slicer)
Thank you in advance for the help! 

Monepieveloce
Frequent Visitor

Thanks for looking into the issue! 
I tried the proposed solution, but I got the count of users at each level only for those users who had an update on the specific month, while users that were at the same status from a previous month were not considered 😞

@Monepieveloce oh sorry, i didn't undestand. But, based on your example, i can't understand what do you add for each month. can you explain me how do you reach the output of july?

July filter applied
Status# Count
12
23
31
41

Thanks you for the reply! 
The status of each user in July is the following, so that is why I get the july outout posted above :

UserStatus in JulyLast change
AAA11/Jul/24
BBB21/Jun/24
CCC21/Jun/24
DDD31/May/24
EEE41/May/24
FFF11/Jun/24
GGG21/Jul/24

@Monepieveloce 

1. Create a separate table for Dates, in my case i named it DateSampleTable, with this code:

DateSampleTable = DISTINCT(SampleTable[Update Date])
2. Create the measure:
CountByUsernameStatus =
VAR VirtualTable =
    CALCULATETABLE(SUMMARIZE(FILTER('SampleTable', SampleTable[Update Date] <= SELECTEDVALUE(DateSampleTable[Update Date])), SampleTable[Username], "Date", MAX(SampleTable[Update Date]), "STATUS", MAX(SampleTable[Current Status])))

RETURN
    COUNTROWS(VirtualTable)
Try it and let me know.
 
BBF

@BeaBF thanks for the answer!
Unfortunately it did not work, since the formula counts the users per status but shows only the users that had an update in the month selected in the slicer, so it does not take into consideration what happened before the month selected. 
What I was able to achieve is the cumulative count of users at each month (but I was not able to show the categorization by status), or the count of users at each status who had an update on that month. I could not find a way to combine the 2 and get the cumulative count of users at each status at the end of the month.

@Monepieveloce the slicer must be an external table, did you do it?

BeaBF_0-1720682101056.png

 

BBF 

@BeaBF 
Yes I did so but it did not work, I believe I followed the same steps but apparently I did something wrong 😞

Monepieveloce_0-1720690414081.png

In the meanwhile I created a table printing the status of each user at the end of each month and I got what I need, but I am afraid this table may slow down the performance

BeaBF
Memorable Member
Memorable Member

@Monepieveloce Hi! You don't need any calculation, you have to construct the table in this way:

BeaBF_0-1720607448522.png

you'll obtain a table with the Status and the count of Users for each Status and you can easily filter the table by a slicer on month, like:

 

BeaBF_1-1720607590673.png

 

But, if you want a measure, you can use:

UsersCount = CALCULATE(DISTINCTCOUNT(SampleTable[Username]), ALLEXCEPT(SampleTable, SampleTable[Current Status], SampleTable[Update Date]))

 

BBF

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.