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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
nok
Advocate II
Advocate II

Column that counts rows from two other columns and compares the result

Hello! I'm having trouble doing something that seems simple.
My table follows this structure:

 

IDSTATUSLAST_STEP
111Not approvedTRUE
111ApprovedTRUE
222ApprovedTRUE
222ApprovedTRUE
222Not approvedFALSE
333ApprovedFALSE
333 FALSE
333ApprovedTRUE
333ApprovedTRUE
444ApprovedTRUE
444 TRUE

I want to create a calculated column that checks, for each ID, if the number of rows where STATUS="Approved" and the number of rows where LAST_STEP=TRUE are the same. If they are the same, then this new column would show "OK" (if not it shows "NOK").

The expected result would be something like this:

IDSTATUSLAST_STEPNEW_COLUMN
111Not approvedTRUENOK
111ApprovedTRUENOK
222ApprovedTRUEOK
222ApprovedTRUEOK
222Not approvedFALSEOK
333ApprovedFALSEOK
333 FALSEOK
333ApprovedTRUEOK
333ApprovedTRUEOK
444ApprovedTRUENOK
444 TRUENOK
2 ACCEPTED SOLUTIONS
DataInsights
Super User
Super User

@nok,

 

Try this calculated column:

 

New Column = 
VAR vID = 'Table'[ID]
VAR vStatusApproved =
    COUNTROWS ( FILTER ( 'Table', 'Table'[ID] = vID && 'Table'[STATUS] = "Approved" ) )
VAR vLastStepTrue =
    COUNTROWS ( FILTER ( 'Table', 'Table'[ID] = vID && 'Table'[LAST_STEP] = TRUE ) )
VAR vResult =
    IF ( vStatusApproved = vLastStepTrue, "OK", "NOK" )
RETURN
    vResult

 

DataInsights_0-1722006608650.png

 

Check your expected result for ID 333. It has three Approved rows and two True rows, hence NOK.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

mickey64
Super User
Super User

For your reference.

I add a 'New_Column' column below.

New_Column = IF(CALCULATE(COUNTX(FILTER('DATA','DATA'[STATUS]="Approved"),'DATA'[STATUS]),ALLEXCEPT('DATA','DATA'[ID]))=CALCULATE(COUNTX(FILTER('DATA','DATA'[LAST_STEP]="true"),'DATA'[LAST_STEP]),ALLEXCEPT('DATA','DATA'[ID])),"OK","NOK")

mickey64_0-1722007348798.png

 

View solution in original post

3 REPLIES 3
SachinNandanwar
Super User
Super User

Just incase if you want it in form of a table 

Table = ADDCOLUMNS (
    SUMMARIZE (
        Step,
        Step[LAST_STEP],
        Step[ID],
        Step[STATUS]
    ),
   "New_Column",
    VAR ApprovedCount = 
        CALCULATE (
            COUNTROWS ( Step ),
            ALLEXCEPT(Step,Step[ID]),
            Step[STATUS] = "Approved"
        )
        VAR StatusCount = 
        CALCULATE (
            COUNTROWS ( Step ),
            ALLEXCEPT(Step,Step[ID]),
            Step[LAST_STEP] = "TRUE"
        )

      RETURN IF (ApprovedCount=StatusCount,  "OK","NOK")
)


I never knew its possible to use variables in combination with Summarize. Learned something new.



Regards,
Sachin
Check out my Blog
mickey64
Super User
Super User

For your reference.

I add a 'New_Column' column below.

New_Column = IF(CALCULATE(COUNTX(FILTER('DATA','DATA'[STATUS]="Approved"),'DATA'[STATUS]),ALLEXCEPT('DATA','DATA'[ID]))=CALCULATE(COUNTX(FILTER('DATA','DATA'[LAST_STEP]="true"),'DATA'[LAST_STEP]),ALLEXCEPT('DATA','DATA'[ID])),"OK","NOK")

mickey64_0-1722007348798.png

 

DataInsights
Super User
Super User

@nok,

 

Try this calculated column:

 

New Column = 
VAR vID = 'Table'[ID]
VAR vStatusApproved =
    COUNTROWS ( FILTER ( 'Table', 'Table'[ID] = vID && 'Table'[STATUS] = "Approved" ) )
VAR vLastStepTrue =
    COUNTROWS ( FILTER ( 'Table', 'Table'[ID] = vID && 'Table'[LAST_STEP] = TRUE ) )
VAR vResult =
    IF ( vStatusApproved = vLastStepTrue, "OK", "NOK" )
RETURN
    vResult

 

DataInsights_0-1722006608650.png

 

Check your expected result for ID 333. It has three Approved rows and two True rows, hence NOK.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors