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
Anonymous
Not applicable

Count entries for a period of time

I need to count a "Test Script ID" for the period (each year/month) that the script remained in State=Closed and then once the script changes to State=Decomissioned OR Validated=Out of Scope, I would like it to stop counting the script for the year/month.

See the table below.
Note: The FirstStatusChangedDate is what I'm using in my date slicer.

Example of current table:

Test Script IDStateValidatedFirstStatusChangedDate
6ClosedNot Analysed22/02/2017 15:14
6ClosedNot Started22/02/2017 15:14
6ClosedTicket22/02/2017 15:14
6ClosedValidated22/02/2017 15:14
6DecomissionedNot Analysed6/04/2020 12:55
8Closed 22/02/2017 15:14
8ClosedBeing Tested22/02/2017 15:14
8ClosedNot Analysed22/02/2017 15:14
8ClosedValidated22/02/2017 15:14
8DecomissionedNot Analysed6/04/2020 12:55
9Closed 22/02/2017 15:14
9ClosedNot Started22/02/2017 15:14
9ClosedOut of Scope10/08/2019 15:14
9ClosedValidated2/11/2019 15:14
9DecomissionedOut of Scope27/04/2020 14:36
32DecomissionedNot Analysed6/02/2018 15:27
36ClosedNot Analysed22/02/2017 15:14
36ClosedNot Started22/02/2017 15:14
36ClosedValidated22/02/2017 15:14
36DecomissionedNot Analysed6/04/2020 12:51



Expected Result:
Script ID = 6, should show from 22/02/2017 until 05/04/2020 because it got decommisssioned on 06/04/2020 (it should count each month, so if I select Feb/17 it should show the script, if I select Mar/17, if I select Apr/17 it should show the script and so on. But if I just select year=2017 in my slicer, it should count as only 1 script, if I select year=2018, it should count as 1 script and so on for year selection, still showing each month until 05/04/2020, but again if I select year=2020, it should show as 1 script).
Script ID = 8, should show from 22/02/2017 until 05/04/2020.
Script ID = 9, should show from 22/02/2017 until 09/08/2019, then it should stop showing from 10/08/2019 until 01/11/2019 (Validated=Out of Scope) and then show again from 02/11/2019 until 26/04/2020 and then stop showing from 27/04/2020.
Script ID = 32, should never show.
Script ID = 36, should show from 22/02/2017 until 05/04/2020.


Please let me know the step-by-step of where to add your suggestions in Power BI as I'm still very basic.

Thanks

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

Try adding this as Calculated COLUMNS in DAX:

ScriptRank = RANKX(FILTER(Script, Script[Test Script ID]=EARLIER(Script[Test Script ID])), Script[FirstStatusChangedDate], ,ASC,Dense)

ValidationCount = COUNTROWS(FILTER(Script, Script[Test Script ID]=EARLIER(Script[Test Script ID]) && Script[Validated]="Validated" && Script[ScriptRank]<=EARLIER(Script[ScriptRank] )))

OutOfScopeCount = COUNTROWS(FILTER(Script, Script[Test Script ID]=EARLIER(Script[Test Script ID]) && Script[Validated]="Out of Scope" && Script[ScriptRank]<=EARLIER(Script[ScriptRank] )))

Activity = IF(Script[State]="Decomissioned" || Script[Validated]="Out of Scope" || Script[ValidationCount]&lt;script[OutOfScopeCount] , "Inactive", "Active")

Then filter the visual for when Activity = Active in addition to the date filter you already have.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

1 REPLY 1
AllisonKennedy
Super User
Super User

Try adding this as Calculated COLUMNS in DAX:

ScriptRank = RANKX(FILTER(Script, Script[Test Script ID]=EARLIER(Script[Test Script ID])), Script[FirstStatusChangedDate], ,ASC,Dense)

ValidationCount = COUNTROWS(FILTER(Script, Script[Test Script ID]=EARLIER(Script[Test Script ID]) && Script[Validated]="Validated" && Script[ScriptRank]<=EARLIER(Script[ScriptRank] )))

OutOfScopeCount = COUNTROWS(FILTER(Script, Script[Test Script ID]=EARLIER(Script[Test Script ID]) && Script[Validated]="Out of Scope" && Script[ScriptRank]<=EARLIER(Script[ScriptRank] )))

Activity = IF(Script[State]="Decomissioned" || Script[Validated]="Out of Scope" || Script[ValidationCount]&lt;script[OutOfScopeCount] , "Inactive", "Active")

Then filter the visual for when Activity = Active in addition to the date filter you already have.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.