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

CALCULATE based on two criteria in another column

Hi, I need to count
IF Unique ID has "Apples" AND "Oranges" then count only "Apples"

IF Unique ID has "Apples" AND any other catergory, count as 1

 

I assume this is some kind of Filter Calculate combination but I cannot figure it out

Thank you for your assistance!
 Capture.PNG

3 ACCEPTED SOLUTIONS
smpa01
Super User
Super User

@StoryofData  you can write a measure like this

 

Measure = 
VAR _left =
    SELECTCOLUMNS (
        FILTER ( ALL ( 'Table' ), 'Table'[UID] = MAX ( 'Table'[UID] ) ),
        "cat", 'Table'[Category] & ""
    )
VAR _filt =
    CONTAINSROW ( _left, "apple" )
VAR __count =
    IF (
        _filt = TRUE (),
        COUNTROWS (
            FILTER ( VALUES ( 'Table'[Category] ), 'Table'[Category] <> "Orange" )
        ),
        COUNTROWS ( 'Table' )
    )
RETURN
    __count
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

I wrote as

VAR _left
and not 
VAR_left
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

try rhis

Column =
VAR _left =
    SELECTCOLUMNS (
        FILTER ( 'Table', 'Table'[UID] = EARLIER ( 'Table'[UID] ) ),
        "cat", 'Table'[Category] & ""
    )
VAR _filt =
    CONTAINSROW ( _left, "apple" )
VAR __count =
    IF (
        _filt = TRUE (),
        CALCULATE ( COUNTROWS ( FILTER ( 'Table', 'Table'[Category] <> "Orange" ) ) ),
        CALCULATE ( COUNTROWS ( 'Table' ) )
    )
RETURN
    __count
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

9 REPLIES 9
smpa01
Super User
Super User

@StoryofData  you can write a measure like this

 

Measure = 
VAR _left =
    SELECTCOLUMNS (
        FILTER ( ALL ( 'Table' ), 'Table'[UID] = MAX ( 'Table'[UID] ) ),
        "cat", 'Table'[Category] & ""
    )
VAR _filt =
    CONTAINSROW ( _left, "apple" )
VAR __count =
    IF (
        _filt = TRUE (),
        COUNTROWS (
            FILTER ( VALUES ( 'Table'[Category] ), 'Table'[Category] <> "Orange" )
        ),
        COUNTROWS ( 'Table' )
    )
RETURN
    __count
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Is it possible to convert this result to a new column rather than a count?
If I am asking too much, I apologize 

@StoryofData  what is the desired output

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

New Column with a count of 1 or 0 like I have in my picture above
I realize that straight up count will not let me do futher analysis, I need an actual column that will show 1 or 0 depending on category

try rhis

Column =
VAR _left =
    SELECTCOLUMNS (
        FILTER ( 'Table', 'Table'[UID] = EARLIER ( 'Table'[UID] ) ),
        "cat", 'Table'[Category] & ""
    )
VAR _filt =
    CONTAINSROW ( _left, "apple" )
VAR __count =
    IF (
        _filt = TRUE (),
        CALCULATE ( COUNTROWS ( FILTER ( 'Table', 'Table'[Category] <> "Orange" ) ) ),
        CALCULATE ( COUNTROWS ( 'Table' ) )
    )
RETURN
    __count
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

THANK YOU SO MUCH!

thank you so much for taking the time, for some reason, VAR_left is underlining as an error... 

I wrote as

VAR _left
and not 
VAR_left
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Pardon, I see my error, this works! Thank you!

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