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
yashwant101
Helper III
Helper III

Need to calculate count based on last status

Hi all,

 

I am creating a chart where I need to take the count of patients whose last status was active.

Below is the screenshot of the data

yashwant101_0-1710325970892.png

 

I have created below measures to get the latest status and then count

 

Last Status =
VAR _Max_Dt = SUMX(SUMMARIZE('Table','Table'[Patient], "Max Dt", MAX('Table'[Dt])), [Max Dt])
VAR _MaxStat = LOOKUPVALUE('Table'[Stat], 'Table'[Dt], _Max_Dt)
RETURN
_MaxStat
 
 
Total Patient =
CALCULATE(DISTINCTCOUNT('Table'[Patient]), ALL('Table'[Dt]), 'Table'[Dt]<= MAX('Table'[Dt]), [Last Status] = "Active")
 
The last status one works fine but when I try to calculate total patients, I am not able to put the last status measure in the dax.
 
Any help is highly appreciated.
 
Regrads,
Yashwant Mishra
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @yashwant101 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Total Patient =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Patient] ),
    FILTER (
        SUMMARIZE ( 'Table', [Patient], "last status", [Last Status] ),
        [last status] = "Active"
    )
)

(3) Then the result is as follows.

vtangjiemsft_0-1710382079524.png

Best Regards,

Neeko Tang

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

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Ashish_Mathur_0-1710386225119.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Ashish_Mathur_0-1710386225119.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur @Anonymous ,

 

Thanks for your super helful replies. One thing I missed in the requirement. The patient whose last status was active on any date prior to the last date os selection should also be counted. Eg. In the ss below P2 & P3 both should be counted in the given selection as last status of P2 was active even though prior to the selection:

yashwant101_0-1710390901558.png

But the last date selection should be maitained.

 

Regards,

Yashwant

Your requirement is confusion and sharing a screenshot is useless.  Share some data to work with and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @yashwant101 ,

 

We can create a table.

Table 2 = VALUES('Table'[Patient])

Then we can update the Total Patient measure.

Total Patient = 
var _table=SUMMARIZE ( ALL('Table'), [Patient], "last status", [Last Status] )
return COUNTROWS(FILTER(_table,[last status]="Active" && [Patient] in VALUES('Table 2'[Patient])))

vtangjiemsft_0-1710395199056.png

Best Regards,

Neeko Tang

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

Anonymous
Not applicable

Hi @yashwant101 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Total Patient =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Patient] ),
    FILTER (
        SUMMARIZE ( 'Table', [Patient], "last status", [Last Status] ),
        [last status] = "Active"
    )
)

(3) Then the result is as follows.

vtangjiemsft_0-1710382079524.png

Best Regards,

Neeko Tang

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

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.

Top Solution Authors