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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Fisask
Regular Visitor

Dax Count concurrent identical values

I have a table of projects . These have overall status reports generated every week . I need to count the concurrent status from the last report going backwards Note  different projectNote different projectfor each project . So if for a particular project ,the status has been the same for 5 weeks I need  to show 5 .

Thanks

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

Hi , @Fisask 

According to your description, you want to group by [ALL.project] and show the maximum number of consecutive occurrences of the same [ALL.overall_health]. Right?

Here are the steps you can follow:

(1) This is my test data :

vyueyunzhmsft_0-1664160060912.png

(2) You can click "New column" to create two calculated columns:

 

flag = 
var _current_pro='Test'[ALL.project]
var _pro_max_date= MAXX( FILTER('Test', 'Test'[ALL.project]=_current_pro ) , [ALL.as_on])
var _pro_color=MAXX( FILTER('Test','Test'[ALL.project]=_current_pro && 'Test'[ALL.as_on] = _pro_max_date),[ALL.overall_health] )

return 
IF('Test'[ALL.overall_health]=_pro_color ,1,-1)
Count = 
var _current_pro='Test'[ALL.project]
var _pro_m1=MAXX( FILTER( 'Test' , 'Test'[ALL.project]=_current_pro && 'Test'[flag]= -1 ),[ALL.as_on])
return
SUMX( FILTER( 'Test','Test'[ALL.project]=_current_pro && 'Test'[ALL.as_on] >_pro_m1 ),[flag])

 

vyueyunzhmsft_1-1664160154877.png

(3)Then we can put the [Count] and the [ALL.project] field in the table visual.The result is as follows:

vyueyunzhmsft_2-1664160257087.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

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

4 REPLIES 4
v-yueyunzh-msft
Community Support
Community Support

Hi , @Fisask 

According to your description, you want to group by [ALL.project] and show the maximum number of consecutive occurrences of the same [ALL.overall_health]. Right?

Here are the steps you can follow:

(1) This is my test data :

vyueyunzhmsft_0-1664160060912.png

(2) You can click "New column" to create two calculated columns:

 

flag = 
var _current_pro='Test'[ALL.project]
var _pro_max_date= MAXX( FILTER('Test', 'Test'[ALL.project]=_current_pro ) , [ALL.as_on])
var _pro_color=MAXX( FILTER('Test','Test'[ALL.project]=_current_pro && 'Test'[ALL.as_on] = _pro_max_date),[ALL.overall_health] )

return 
IF('Test'[ALL.overall_health]=_pro_color ,1,-1)
Count = 
var _current_pro='Test'[ALL.project]
var _pro_m1=MAXX( FILTER( 'Test' , 'Test'[ALL.project]=_current_pro && 'Test'[flag]= -1 ),[ALL.as_on])
return
SUMX( FILTER( 'Test','Test'[ALL.project]=_current_pro && 'Test'[ALL.as_on] >_pro_m1 ),[flag])

 

vyueyunzhmsft_1-1664160154877.png

(3)Then we can put the [Count] and the [ALL.project] field in the table visual.The result is as follows:

vyueyunzhmsft_2-1664160257087.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

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

 

Thank you so much . The logic is very clear . I still have an issue but I think I can work it out from here 

daXtreme
Solution Sage
Solution Sage

Not clear. Please make it more understandable. Thanks.

 

How to Get Your Question Answered Quickly - Microsoft Power BI Community

Hi,  I will attempt to make my problem clearer. In a database table I have status reports for about 200 projects. These are produced every week for each project . The status is a colour , Red, Amber  or Green. 
I simply want to show in my dashboard the number of weeks, going backwards in time from the current week, the status has remained the same for each project. So if a project status is Green this week and has been Green for the last 4 weeks .I want to display that the project has been Green for 4 weeeks .

sounds simple but it's counting consecutive identical values and I can't solve it.

 

many thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors