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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
imranamikhan
Helper V
Helper V

Count IFS By Latest Date

Hello,

 

I have a number of records with duplicates. Each record has a timestamp (date & time) and a status column.

 

Capture.PNG

 

I am using the following DAX expression to count records by the most recent timestamp. How do I modify this expression to also include only “Completed” records in the count?

 

 

 

LatestRecord =

VAR MostRencentTime =

    CALCULATE (

        MAX ( TaskTable[RecordTimestamp]),

        ALLEXCEPT ( TaskTable, TaskTable[Task ID] )

    )

RETURN

    IF ( MostRencentTime = MAX ( TaskTable[RecordTimestamp] ), 1, 0 )

 

 

 

Best regards,

ImranAmi

 

2 ACCEPTED SOLUTIONS

Hi @imranamikhan ,

I'm not sure how you want the count to be calculated exactly, but try this:

UniqueCount = 
VAR _max =
    CALCULATE (
        MAX ( TaskTable[RecordTimestamp] ),
        ALLEXCEPT ( TaskTable, TaskTable[Task ID] )
    )
RETURN
    CALCULATE (
        COUNTROWS ( TaskTable ),
        FILTER (
            ALLEXCEPT ( TaskTable, TaskTable[Task ID] ),
            TaskTable[Status] = "Completed"
                && TaskTable[RecordTimestamp] = _max
        )
    )










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

@imranamikhan

Try this:

Solution =
VAR MaxDate =
    MAX ( TaskTable[RecordTimestamp] )
VAR _STATUS =
    FILTER (
        TaskTable,
        TaskTable[Status] = "Completed"
            && TaskTable[RecordTimestamp] = MaxDate
    )
VAR _Count =
    COUNTROWS ( _STATUS )
RETURN
    _Count

Bless you!
Vivek

If it helps, please mark it as a solution
Congratulations would be a cherry on top 🙂

https://www.vivran.in/

Connect connects on LinkedIn

View solution in original post

12 REPLIES 12
v-frfei-msft
Community Support
Community Support

Hi @imranamikhan ,

 

Does that meet your requirement?

LatestRecord = 
VAR MostRencentTime =
    CALCULATE (
        MAX ( TaskTable[RecordTimestamp] ),
        ALLEXCEPT ( TaskTable, TaskTable[Task ID] )
    )
VAR a =
    IF (
        MostRencentTime = MAX ( TaskTable[RecordTimestamp] )
            && MAX ( TaskTable[Statue] ) = "Completed",
        1,
        0
    )
RETURN
    a
LatestRecord—1 = 
SUMX(TaskTable,[LatestRecord])

Capture.PNG

 

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks @danextian. I am working with a push dataset so I am limited to using measures only. The suggested DAX is only returning a date, not a count.

 

Thanks again @v-frfei-msft. Unfortunately the suggested measure is producing incorrect results. I have attached my working file via OneDrive here:

 

https://1drv.ms/u/s!AkH_PeScw-iuhpd6-3DAVBy805z36A?e=gyY196 

 

Could you please take a look when you have a moment?

 

Hi @imranamikhan ,

I'm not sure how you want the count to be calculated exactly, but try this:

UniqueCount = 
VAR _max =
    CALCULATE (
        MAX ( TaskTable[RecordTimestamp] ),
        ALLEXCEPT ( TaskTable, TaskTable[Task ID] )
    )
RETURN
    CALCULATE (
        COUNTROWS ( TaskTable ),
        FILTER (
            ALLEXCEPT ( TaskTable, TaskTable[Task ID] ),
            TaskTable[Status] = "Completed"
                && TaskTable[RecordTimestamp] = _max
        )
    )










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Apologies this did work - the error was my part. Thank you very much.

 

Hi @danextian Thanks for your help. I guess I am not being clear on the requirement because the solution is producing the same incorrect value as the measure kindly provided by @v-frfei-msft 

 

I have a set of data. Column A contains a list of unique entries (Task ID), Column B contains a Status value, and Column C contains a Time Stamp. When the data is refreshed, new entries are appended to the existing data with the same IDs but with an updated Status. I want to count the number of occurrences of a specific Status (such as "Completed") by the latest record. It is simple to do this in Excel for example, you count the number of entries based on the latest Time Stamp AND filter that count by a Status of “Completed”.

 

E.g.

=COUNTIFS(column B,MAX(column b),(column c),”Completed”)

 

In the below example, 23/03/2020  09:12 is the latest refresh date. So I want to count the number of entries with that date AND fitler the result by a status of “Completed”. The OneDrive sample file includes the spreadsheet below. Does this clarify?

 

Capture.PNG

 

best regards,

ImranAmi

 

Hi - if anyone has any possible solutions that would be appreciated.

 

best regards,

ImranAmi

 

@imranamikhan

Try this:

Solution =
VAR MaxDate =
    MAX ( TaskTable[RecordTimestamp] )
VAR _STATUS =
    FILTER (
        TaskTable,
        TaskTable[Status] = "Completed"
            && TaskTable[RecordTimestamp] = MaxDate
    )
VAR _Count =
    COUNTROWS ( _STATUS )
RETURN
    _Count

Bless you!
Vivek

If it helps, please mark it as a solution
Congratulations would be a cherry on top 🙂

https://www.vivran.in/

Connect connects on LinkedIn

Thank you very much

 

v-frfei-msft
Community Support
Community Support

Hi @imranamikhan ,

 

Have a try please.

LatestRecord =
VAR MostRencentTime =
    CALCULATE (
        MAX ( TaskTable[RecordTimestamp] ),
        FILTER (
            ALLEXCEPT ( TaskTable, TaskTable[Task ID] ),
            TaskTable[Status] = "Completed"
        )
    )
RETURN
    IF ( MostRencentTime = MAX ( TaskTable[RecordTimestamp] ), 1, 0 )

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks @v-frfei-msft and @vivran22.

 

I have tried both options but both return a value of 1, whereas what I am looking for is a count of records with a "Completed" status by the most recent time stamp. If I could translate the DAX into an Excel formula, it would look like this:

=COUNTIFS(
Table_TaskList[RecordTimestamp],
MAX(Table_TaskList[RecordTimestamp]),
Table_TaskList[ProcessStatus],"Completed"
)

 

Hi @imranamikhan ,

 

Have you tried using the formula of @v-frfei-msft  and @vivran22  in a calculated column then use the result for your count? If you are going to use a measure, the formula should be something like below:

 

Count =
CALCULATE (
        MAX ( TaskTable[RecordTimestamp] ),
        FILTER (
            ALLEXCEPT ( TaskTable, TaskTable[Task ID] ),
            TaskTable[Status] = "Completed"
        )
    )

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
vivran22
Community Champion
Community Champion

Hello @imranamikhan 

 

You may try:

 

LatestRecord =

VAR MostRencentTime =

    CALCULATE (

        MAX ( TaskTable[RecordTimestamp]),

        ALLEXCEPT ( TaskTable, TaskTable[Task ID] ),
        KEEPFILTERS(TaskTable[Status] = "Completed"

    )

RETURN

    IF ( MostRencentTime = MAX ( TaskTable[RecordTimestamp] ), 1, 0 

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂

https://www.vivran.in/

Connect on LinkedIn

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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