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! Request now

Reply
jmscrx
Helper I
Helper I

Formula to evaluate several pieces of information and count the resulting number of times?

Hi folks, have one that is a bit over my head as a beginner to Dax and Power BI. I have data that looks like the following.

 

Control NumberICT Record NameCreated DateStatusCA Testing Results
CRX-2019-1Control Test-4297/1/2020 12:00COMPLETEOperating as Expected
CRX-2019-1Control Test-8991/1/2021 12:01ASSIGNED 
CRX-2019-10Control Test-3997/1/2020 12:00COMPLETEOperating with Findings: Corrective Action not Required
CRX-2019-10Control Test-8691/1/2021 12:01COMPLETEOperating as Expected
CRX-2019-10Control Test-9422/1/2021 12:01NOT_ASSIGNED 
CRX-2019-100Control Test-9311/1/2021 12:01NOT_ASSIGNEDNot Operating as Expected: Corrective & Preventative Action Required
CRX-2019-102Control Test-9361/1/2021 12:01NOT_ASSIGNED 
CRX-2019-104Control Test-9471/1/2021 17:01IN_PROGRESS 
CRX-2019-104Control Test-10551/27/2021 18:16NOT_ASSIGNED 
CRX-2019-11Control Test-8821/1/2021 12:01NOT_ASSIGNEDIncomplete: Additional Evidence Required

 

What I'd like to be able to do is create a measure (or whatever is similar and most appropriate) to calculate the total number of unique controls (Control Number column) where the most recent control test that is marked COMPLETE (Created Date and Status columns) has a result (CA Testing Results column) of either Not Operating as Expected... or Operating with Findings... Please note that a control can have multiple outstanding control tests (ICT Record Name column), which is why I need to ensure I'm checking the status of all tests for a control of being COMPLETE then of those, determing the most recent one and including it in my count based on the requirements for the CA Testing Results column as stated above.

 

As an example, if we look at control CRX-2019-1 (first 2 rows), there are 2 outstanding control tests. Of those, only one is COMPLETE, so that's the only one I would consider however the results are Operating as Expected so I would not count anything in my final count here. However if we look at CRX-2019-10, which has 3 outstanding control tests. 2 of these tests are marked as COMPLETE so I would evaluate those and of those, the most recent is from 1/1/21, however the results from this one are Operating as Expected so I would not count this either. Had the results been either Not Operating as Expected... or Operating with Findings... then I would have counted this in my overall count.

 

Hopefully this makes sense, thanks!

3 REPLIES 3
Anonymous
Not applicable

// The model must have a date table, Dates,
// that will be connected to the fact table
// T on Dates[Date] = T[Created Date].

// According to Best Practices all fields in
// the fact table should be hidden and slicing
// must be performed by dimensions only.

// This measure will respond to any selections
// in any dimensions. If you want to suppress
// honoring any filters, you'll have to adjust
// the measure. I don't do it since I can't
// figure out from your description if you need
// that. For instance, if you slice by Status =
// "Assigned", then the measure will return BLANK
// since there can't be any entries with a status of
// "complete" found in the current context.

[Your Measure] =
var vControlNumsWithLatestCreatedDate =
    CALCULATETABLE(
        ADDCOLUMNS(
            DISTINCT( T[Control Number] ),
            // Get the most recent date in
            // the current context.
            "@MostRecentDate",
                CALCULATE(
                    MAX( T[Created Date] )
                )
        ),
        KEEPFILTERS( T[Status] = "complete" )
    )
var vControlNumsAboveWithAppropriateResult =
    CALCULATETABLE(
        T,
        TREATAS(
            vControlNumsWithLatestCreatedDate,
            T[Control Number],
            T[Created Date]
        ),
        KEEPFILTERS(
            T[CA Testing Results] in {
                "not operating as expected",
                "operating with findings"
            }
        )
    )
var Result =
    COUNTROWS( vControlNumsAboveWithAppropriateResult )
return
    Result
ERD
Community Champion
Community Champion

Hello @jmscrx ,

Here is an option you can try:

 

#Measure = 
COUNTROWS(
    FILTER (
        GENERATE (
            SUMMARIZECOLUMNS ( 'Table'[Control Number], 'Table'[Status] ),
            CALCULATETABLE (
                TOPN (
                    1,
                    SUMMARIZE (
                        'Table',
                        'Table'[Created Date],
                        'Table'[CA Testing Results]
                    ),
                    'Table'[Created Date]
                ))),
        'Table'[CA Testing Results] <> "Operating as Expected"
            && 'Table'[Status] = "COMPLETE"
    )
)

 

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Hi @ERD 

 

Your measure is certainly wrong as it does not adhere to the specification as put forward in the description.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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.