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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

counting records before a specific date

I am very new to power Bi and DAX and need help. I have records of dates for when a account was created(Activated Date) for a user. The records go back to 2012. I am showing data for each month of 2022. And I want to show how many people were still active before the last date of each month. I dont want to count people who have a In-Activated date or who have Activated date after the respective month. right now the formula looks like 

CALCULATE(COUNTROWS('RegisteredUsers'[User Name]),'RegisteredUsers'[In-Activated Date]="NULL")

Abhijay_0-1657718167296.png

 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here I create a sample to have a test.

RicoZhou_1-1658134017338.png

 

DimDate table:

DimDate = 
ADDCOLUMNS( CALENDAR(DATE(2022,01,01),DATE(2022,12,31)),"Year",YEAR([Date]),"Month",MONTH([Date]),"MonthLongName",FORMAT([Date],"MMMM"))

Please try this code to create a measure to count the active user before each month ending date.

Measure:

Active User =
VAR _MAXDATE =
    MAX ( DimDate[Date] )
RETURN
    CALCULATE (
        COUNT ( RegisteredUsers[User Name] ),
        FILTER (
            RegisteredUsers,
            RegisteredUsers[Activated Date] <= _MAXDATE
                && OR (
                    RegisteredUsers[In-Activated Date] = BLANK (),
                    RegisteredUsers[In-Activated Date] > _MAXDATE
                )
        )
    )

Result is as below.

RicoZhou_0-1658134009163.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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here I create a sample to have a test.

RicoZhou_1-1658134017338.png

 

DimDate table:

DimDate = 
ADDCOLUMNS( CALENDAR(DATE(2022,01,01),DATE(2022,12,31)),"Year",YEAR([Date]),"Month",MONTH([Date]),"MonthLongName",FORMAT([Date],"MMMM"))

Please try this code to create a measure to count the active user before each month ending date.

Measure:

Active User =
VAR _MAXDATE =
    MAX ( DimDate[Date] )
RETURN
    CALCULATE (
        COUNT ( RegisteredUsers[User Name] ),
        FILTER (
            RegisteredUsers,
            RegisteredUsers[Activated Date] <= _MAXDATE
                && OR (
                    RegisteredUsers[In-Activated Date] = BLANK (),
                    RegisteredUsers[In-Activated Date] > _MAXDATE
                )
        )
    )

Result is as below.

RicoZhou_0-1658134009163.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.

amitchandak
Super User
Super User

@Anonymous , I think You need something similar to this HR blog

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970

 

Or check the attached files

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors