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
Fiejj
Regular Visitor

Check if all values in category are positive/negative

Hi everyone,

 

I'm struggling with this small problem which is probably easy to solve. I'm working in DirectQuery mode. Let's say I have several categories each having multiple values:

 

Cat A           0.47
                    0.48

                  -0.37

                  -0.74

Cat B            0.85

                    0.67

                    0.84

                    0.63

 

I want Power BI to check these four values and return for example '1' for the particular category if all four values are positive, and '-1' if all four values are negative. Otherwise it should return '0'. Is this possible using DAX? I have tried SUM (sum should be 4 or -4), AVERAGE and the SIGN function, but no success so far. I have no experience using queries/SQL by the way.

 

Thanks!

2 ACCEPTED SOLUTIONS
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @Fiejj

 

I created the following table in SQL and connected to it using Direct Query.

 

Cat	n
Cat A	0.47
Cat A	0.48
Cat A	-0.37
Cat A	-0.74
Cat B	0.85
Cat B	0.67
Cat B	0.84
Cat B	0.63

I then added the following calulated column to that table in Power BI

 

Column = if('N'[n]<0,1,2)

This meant I could now create a measure to test if all the values in the column were the same for each category

 

Is Same = 
var MaxValue = CALCULATE(MAX('N'[Column]),ALLEXCEPT('N',N[Cat]))
var MinValue = CALCULATE(MIN('N'[Column]),ALLEXCEPT('N',N[Cat]))
var Result = IF(MaxValue=MinValue,"All Same","Different")
Return Result

How does that look?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Fiejj,

 

In your scenario, you can first create a calculated column:

flag =
IF ( testpositivenegative[value] > 0, 1, 0 )

Then, create a measure to check if all values in category are positive/negative and show corresponding value.

Count =
IF (
    CALCULATE (
        SUM ( testpositivenegative[flag] ),
        ALLEXCEPT ( testpositivenegative, testpositivenegative[Category] )
    )
        = 4,
    1,
    IF (
        CALCULATE (
            SUM ( testpositivenegative[flag] ),
            ALLEXCEPT ( testpositivenegative, testpositivenegative[Category] )
        )
            = -4,
        -1,
        0
    )
)

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

3 REPLIES 3
Fiejj
Regular Visitor

Thanks everyone, it worked, totally forgot to reply but really appreciate your help!

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Fiejj,

 

In your scenario, you can first create a calculated column:

flag =
IF ( testpositivenegative[value] > 0, 1, 0 )

Then, create a measure to check if all values in category are positive/negative and show corresponding value.

Count =
IF (
    CALCULATE (
        SUM ( testpositivenegative[flag] ),
        ALLEXCEPT ( testpositivenegative, testpositivenegative[Category] )
    )
        = 4,
    1,
    IF (
        CALCULATE (
            SUM ( testpositivenegative[flag] ),
            ALLEXCEPT ( testpositivenegative, testpositivenegative[Category] )
        )
            = -4,
        -1,
        0
    )
)

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @Fiejj

 

I created the following table in SQL and connected to it using Direct Query.

 

Cat	n
Cat A	0.47
Cat A	0.48
Cat A	-0.37
Cat A	-0.74
Cat B	0.85
Cat B	0.67
Cat B	0.84
Cat B	0.63

I then added the following calulated column to that table in Power BI

 

Column = if('N'[n]<0,1,2)

This meant I could now create a measure to test if all the values in the column were the same for each category

 

Is Same = 
var MaxValue = CALCULATE(MAX('N'[Column]),ALLEXCEPT('N',N[Cat]))
var MinValue = CALCULATE(MIN('N'[Column]),ALLEXCEPT('N',N[Cat]))
var Result = IF(MaxValue=MinValue,"All Same","Different")
Return Result

How does that look?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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