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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
anthonymachado
Frequent Visitor

Get count of active statuses from event log only if they are the most recent status per account

I have a table of account status changes and I want to let the user set a date to see how many accounts had status "Active" at that date. I currently have a slicer that removes status updates after a certain date, but I need to write a DAX measure to get a count of the remaining "Active" statuses ONLY IF they are the most recent status for that account ID.

 

I've tried many different ways to do this and I can't seem to get an accurate number. I can't do it in Power Query because it needs to be evaluated after the user changes the slicer, so it has to be done in a DAX measure.

 

Here is some sample data from the table:

 

Account IDStatusStatus Updated
56147Active10/7/2024 19:35
56147Install Scheduled9/24/2024 19:16
56147Pending Drop9/19/2024 20:19
56147Pending Drop9/27/2024 20:53
56147Pending Install10/3/2024 21:11
56147Inactive7/16/2025 17:44
58004Pre-Drop CS Contact9/10/2025 5:58
58004Pending Drop9/10/2025 20:39
58004Drop Complete9/19/2025 10:59
58004Install Scheduled9/19/2025 15:54
58004Active9/23/2025 20:19
1 ACCEPTED SOLUTION
ThxAlot
Super User
Super User

ThxAlot_0-1761610186508.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

6 REPLIES 6
Kedar_Pande
Super User
Super User

Active Accounts at Date =
VAR SelectedDate = MAX('DateTable'[Date])
RETURN
COUNTROWS(
FILTER(
SUMMARIZE(
FILTER(
ALL('StatusTable'),
'StatusTable'[Status Updated] <= SelectedDate
),
'StatusTable'[Account ID],
"LastStatus",
CALCULATE(
LASTNONBLANK('StatusTable'[Status], 1),
'StatusTable'[Status Updated] <= SelectedDate
)
),
[LastStatus] = "Active"
)
)

 

If this answer helped, please click Kudos or mark as Solution.
-Kedar
LinkedIn: https://www.linkedin.com/in/kedar-pande

Nasif_Azam
Super User
Super User

Hey  @anthonymachado ,

Step-by-Step Implementation:

1) Make sure your data is loaded properly, let’s call the table StatusLog in Power BI.  

2) Ensure your date slicer is set up as Show data "before" or "between". 

3) Create the DAX Measure:

Active Accounts (as of slicer) :=
VAR Accounts = VALUES ( 'StatusLog'[Account ID] )
RETURN
SUMX (
    Accounts,
    VAR Acc = 'StatusLog'[Account ID]
    VAR LastDt =
        CALCULATE (
            MAX ( 'StatusLog'[Status Updated] ),
            'StatusLog'[Account ID] = Acc
        )
    VAR LastStatus =
        CALCULATE (
            MAXX (
                FILTER (
                    'StatusLog',
                    'StatusLog'[Account ID] = Acc
                        && 'StatusLog'[Status Updated] = LastDt
                ),
                'StatusLog'[Status]
            )
        )
    RETURN IF ( LastStatus = "Active", 1, 0 )
)

 

4) Add a Card visualization and drag this new measure (Active Accounts (as of slicer) into it.

 

Output:

 Nasif_Azam_0-1761637580877.png

 

Also attached the pbix file.

 

Best Regards,
Nasif Azam



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn
ThxAlot
Super User
Super User

ThxAlot_0-1761610186508.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



This worked great! Mine had Status Updated underlined in red as well but it still worked

parry2k
Super User
Super User

@anthonymachado could you give an example output based on some date selections?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

If we're looking at the sample data, the output would be 1. Since the most recent status for Account ID 58004 is "Active" and the most recent status for Account 56147 is "Inactive" and I want to count the "Active" statuses if they are the most recent status for each account

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.