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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BalaKiran_M
Frequent Visitor

Need help in DAX

Experts, please help me to fix the DAX code as it's erroring out SUM cannot work with values of type string.

 

Flag =
VAR _Cond1=
IF('DW C, S & Comp (2)'[x FD Email Address]<>"FD"
&& (AVERAGE('DW C, S & Comp (2)'[Number Of Orders])>=4 && AVERAGE('DW C, S & Comp (2)'[Number Of Orders])<=7)
&& SUM('DW C, S & Comp (2)'[Complaint Amount])>=230
&& SUM('DW C, S & Comp (2)'[Comp_OrderID])>=3
&& 'DW C, S & Comp (2)'[Yesterday Flag]="Y", "Yes", "No")
VAR _Cond2=
IF('DW C, S & Comp (2)'[x FD Email Address]<>"FD"
&& 'DW C, S & Comp'[Credit % Subtotal]>=0.24
&& (SUM('DW C, S & Comp (2)'[Number Of Orders])>=8 && SUM('DW C, S & Comp (2)'[Number Of Orders])<=9)
&& SUM('DW C, S & Comp (2)'[Comp_OrderID])>=3
&& 'DW C, S & Comp (2)'[Yesterday Flag]="Y", "Yes", "No")
VAR _Cond3=
IF('DW C, S & Comp (2)'[x FD Email Address]<>"FD"
&& 'DW C, S & Comp'[Credit % Subtotal]>=0.22
&& (SUM('DW C, S & Comp (2)'[Number Of Orders])>=10&& SUM('DW C, S & Comp (2)'[Number Of Orders])<=14)
&& SUM('DW C, S & Comp (2)'[Comp_OrderID])>=3
&& 'DW C, S & Comp (2)'[Yesterday Flag]="Y", "Yes", "No")
VAR _Cond4=
IF('DW C, S & Comp (2)'[x FD Email Address]<>"FD"
&& 'DW C, S & Comp'[Credit % Subtotal]>=0.2
&& SUM('DW C, S & Comp (2)'[Number Of Orders])>=15
&& SUM('DW C, S & Comp (2)'[Comp_OrderID])>=3
&& 'DW C, S & Comp (2)'[Yesterday Flag]="Y", "Yes", "No")
RETURN
IF(_Cond1="Yes" || _Cond2="Yes" || _Cond3="Yes" || _Cond4="Yes", "Yes", "No")

BalaKiran_M_0-1679204305796.png

 

1 REPLY 1
HassanAshas
Helper V
Helper V

One of the columns that you are using in the SUM function has a String datatype, which can't be used in the SUM function. 

You need to go into your Power Query or Source level and make sure that the columns you are using in your SUM Function are of numeric datatype. 

 

Alternatively, you can also use Value Function to convert strings into Numeric datatype within your DAX. 

 

Flag =
VAR _Cond1 =
    IF (
        'DW C, S & Comp (2)'[x FD Email Address] <> "FD"
            && (
                AVERAGE ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) >= 4
                    && AVERAGE ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) <= 7
            )
            && SUM ( VALUE('DW C, S & Comp (2)'[Complaint Amount] )) >= 230
            && SUM ( VALUE('DW C, S & Comp (2)'[Comp_OrderID] )) >= 3
            && 'DW C, S & Comp (2)'[Yesterday Flag] = "Y",
        "Yes",
        "No"
    )
VAR _Cond2 =
    IF (
        'DW C, S & Comp (2)'[x FD Email Address] <> "FD"
            && 'DW C, S & Comp'[Credit % Subtotal] >= 0.24
            && (
                SUM ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) >= 8
                    && SUM ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) <= 9
            )
            && SUM ( VALUE('DW C, S & Comp (2)'[Comp_OrderID]) ) >= 3
            && 'DW C, S & Comp (2)'[Yesterday Flag] = "Y",
        "Yes",
        "No"
    )
VAR _Cond3 =
    IF (
        'DW C, S & Comp (2)'[x FD Email Address] <> "FD"
            && 'DW C, S & Comp'[Credit % Subtotal] >= 0.22
            && (
                SUM ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) >= 10
                    && SUM ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) <= 14
            )
            && SUM ( VALUE('DW C, S & Comp (2)'[Comp_OrderID]) ) >= 3
            && 'DW C, S & Comp (2)'[Yesterday Flag] = "Y",
        "Yes",
        "No"
    )
VAR _Cond4 =
    IF (
        'DW C, S & Comp (2)'[x FD Email Address] <> "FD"
            && 'DW C, S & Comp'[Credit % Subtotal] >= 0.2
            && SUM ( VALUE('DW C, S & Comp (2)'[Number Of Orders]) ) >= 15
            && SUM ( VALUE('DW C, S & Comp (2)'[Comp_OrderID]) ) >= 3
            && 'DW C, S & Comp (2)'[Yesterday Flag] = "Y",
        "Yes",
        "No"
    )
RETURN
    IF (
        _Cond1 = "Yes"
            || _Cond2 = "Yes"
            || _Cond3 = "Yes"
            || _Cond4 = "Yes",
        "Yes",
        "No"
    )

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors