cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
giordafrancis
Frequent Visitor

Create a measure for prior and latest count based on last date

qConsider the below table:

idragdate
101red01/06/2020
101red02/06/2020
103red01/06/2020
103green02/06/2020
103green05/06/2020
101green05/06/2020

 

I'm looking to create two measures:

  1. one that tallies the count of all id except the latest submission date (05/06/2020 in this case)
  2. another that only tallies the latest  date

Desired outcome for 1

count_prior   
 redambergreen
1012  
1031 1

 

Desired outcome for 2

count_latest   
 redambergreen
101  1
103  1

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION
mahoneypat
Super User IV
Super User IV

Here are two expressions that should work.

 

Count Latest =
VAR __maxdate =
    CALCULATE ( MAX ( 'Table'[date] ), ALLSELECTED ( 'Table' ) )
RETURN
    CALCULATE ( COUNT ( 'Table'[id] ), 'Table'[date] = __maxdate )


Count Prior =
VAR __maxdate =
    CALCULATE ( MAX ( 'Table'[date] ), ALLSELECTED ( 'Table' ) )
RETURN
    CALCULATE ( COUNT ( 'Table'[id] ), 'Table'[date] < __maxdate )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

1 REPLY 1
mahoneypat
Super User IV
Super User IV

Here are two expressions that should work.

 

Count Latest =
VAR __maxdate =
    CALCULATE ( MAX ( 'Table'[date] ), ALLSELECTED ( 'Table' ) )
RETURN
    CALCULATE ( COUNT ( 'Table'[id] ), 'Table'[date] = __maxdate )


Count Prior =
VAR __maxdate =
    CALCULATE ( MAX ( 'Table'[date] ), ALLSELECTED ( 'Table' ) )
RETURN
    CALCULATE ( COUNT ( 'Table'[id] ), 'Table'[date] < __maxdate )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors