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
Phobos1
Helper I
Helper I

Look for value in subgroup, then put true/false in column for entire subgroup.

Hi all, hope someone can help me out with a formula.

My dataset looks like the table below, now I am trying to create the 'New column' with a formula but can't get it to work right. In the dataset there are different sorts of fruit, they can have a value of 0, 1, 2 or 3. The rule I need to implement is: If a fruit has a zero in the 'count' column for any of it's entries, then the result in 'New column' should be false for all entries of this fruit. Else, it should be true. A fruit can have only one entry, or multiple. I came up with this formula but is doesn't work:

Newcolumn=CALCULATE(IF(MIN('Data fruit' [Count])=0,0,sum('Data fruit'[Count])), FILTER(ALLSELECTED('Data fruit'),'Data fruit' [Name fruit]=EARLIER('Data fruit' [Name fruit])))

 

Phobos1_1-1648021125266.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Phobos1 , 

Please refer to my pbix file to see if it help you.

Create a column.

new column =
VAR _min =
    CALCULATE (
        MIN ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[Fruit] = EARLIER ( 'Table'[Fruit] ) )
    )
RETURN
    IF ( _min = 0, FALSE (), TRUE () )

vpollymsft_1-1648435698844.png

 

Best Regards

Community Support Team _ Polly

 

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

5 REPLIES 5
Phobos1
Helper I
Helper I

This works excellently, it does exactly what I need it to do. Thanks so much for solving this!

Anonymous
Not applicable

Hi @Phobos1 , 

Please refer to my pbix file to see if it help you.

Create a column.

new column =
VAR _min =
    CALCULATE (
        MIN ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[Fruit] = EARLIER ( 'Table'[Fruit] ) )
    )
RETURN
    IF ( _min = 0, FALSE (), TRUE () )

vpollymsft_1-1648435698844.png

 

Best Regards

Community Support Team _ Polly

 

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

 

daXtreme
Solution Sage
Solution Sage

define table Tab = 
SELECTCOLUMNS(
    {
        ("Pear", 2),
        ("Pear", 3),
        ("Pear", 0),
        ("Orange", 1),
        ("Orange", 2),
        ("Cherry", 0)
    },
    "Fruit", [Value1],
    "Count", [Value2]
)
EVALUATE
    ADDCOLUMNS(
        Tab,
        "Your Column",
            var currentFruit = Tab[Fruit]
            var fruitHasNoZeros =
                ISEMPTY(
                    FILTER(
                        Tab,
                        Tab[Fruit] = currentFruit
                        && Tab[Count] = 0
                    )
                )
            return
                fruitHasNoZeros
    )

Run this in DAX Studio, for example. The formula for "Your Column" will do what you want.

rbriga
Impactful Individual
Impactful Individual

The simplest way to achieve this is:

Use this table in PowerQuery to group each fruit by minimum of count.

Here's an example:

let
    Source = Excel.CurrentWorkbook(){[Name="Fruits"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Fruit", type text}, {"Count", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Fruit"}, {{"Min", each List.Min([Count]), type nullable number}})
in
    #"Grouped Rows"

This table will be hidden from the model.

Now use PowerQuery again to flag those Min=0 fruits:

let
    Source = Excel.CurrentWorkbook(){[Name="Fruits"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Fruit", type text}, {"Count", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Fruit"}, MinCount, {"Fruit"}, "MinCount", JoinKind.LeftOuter),
    #"Expanded MinCount" = Table.ExpandTableColumn(#"Merged Queries", "MinCount", {"Min"}, {"Min"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded MinCount", "Test", each if [Min] = 0 then false else true, type logical),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Min"})
in
    #"Removed Columns"

It's not the cleanest way, but it's better than calculated columns.

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

Thanks for the quick reply. I tried to make this work but run into some issues as the fruit and count columns are part of a larger dataset. Is there a way to do something like partition by + rank&select in powerBI and add a calculated column with this to the dataset?

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.