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
Anonymous
Not applicable

Need Help with DAX IF Condition

Hi Community,

 

I'm trying to convert a Custom Column into a Measure in Power BI, but I can this error, can someone help me with this.

 

Error Message below.

 

Error Message: MdxScript(Model) (559, 42) Calculation error in measure '00_MEAS_RATEMIX'[06_Mix_Pack Type 2 Mix]: A table of multiple values was supplied where a single value was expected.

 

 

[9:17 PM] Kadagala, Kuber
 

IF ( MAX(Input[Channel]) = "All", 0, 1 )

* IF ( ( [NR/HL Country Base] ) = 0, 0, 1 )

* IF (

OR (

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Channel])), 1, 0 ) > 0,

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Customer])), 1, 0 ) > 0

),

0,

1

)

* IF (

OR (

MAX(Input[Brand]) = "RESIDUAL STOCK",

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Brand])), 1, 0 ) > 0

),

0,

1

)

* IF ( ABS ( [NR/HL Channel Base] - [NR/HL Channel AC] ) > 500, 0, 1 ) / 1000

 

 

 

It is a Direct Query Mode so it has to be a measue, I cannot make it a column.

 

Thanks in advance

1 ACCEPTED SOLUTION

Ah. Yeah, measures shouldn't need extra aggregations.

 

I think your measure could be simplified quite a bit. I'd suggest starting from something like this:

 

MeasureName =
VAR Channel = SELECTEDVALUE ( Input[Channel] )
VAR Customer = SELECTEDVALUE ( Input[Customer] )
VAR Brand = SELECTEDVALUE ( Input[Brand] )
RETURN
    IF (
        Channel = "All"
            || [NR/HL Country Base] = 0
            || CONTAINSSTRING ( Channel, "CENTRAL" )
            || CONTAINSSTRING ( Customer, "CENTRAL" )
            || Brand = "RESIDUAL STOCK"
            || CONTAINSSTRING ( Brand, "CENTRAL" )
            || ABS ( [NR/HL Channel Base] - [NR/HL Channel AC] ) > 500,
        0,
        1
    ) / 1000

 

Note that CONTAINSSTRING is not case-sensitive, so you don't need upper.

View solution in original post

6 REPLIES 6
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

It's hard to reproduce the scenario, can you share some sample data to us?

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
AlexisOlson
Super User
Super User

You'll need to share the DAX that is throwing the error.

Anonymous
Not applicable

IF ( MAX(Input[Channel]) = "All", 0, 1 )

* IF ( ( [NR/HL Country Base] ) = 0, 0, 1 )

* IF (

OR (

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Channel])), 1, 0 ) > 0,

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Customer])), 1, 0 ) > 0

),

0,

1

)

* IF (

OR (

MAX(Input[Brand]) = "RESIDUAL STOCK",

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Brand])), 1, 0 ) > 0

),

0,

1

)

* IF ( ABS ( [NR/HL Channel Base] - [NR/HL Channel AC] ) > 500, 0, 1 ) / 1000

In a calculated column, I'm guessing [NR/HL Channel Base] and [NR/HL Channel AC] are the values from that particular row. A measure does not have row context, so you need to specify some sort of aggregation to return a single value (e.g. SUM or MAX or SELECTEDVALUE).

 

As a side note, HASONEVALUE returns true or false, so UPPER ( True / False ) probably isn't what you actually want.

Anonymous
Not applicable

NR/HL Channel AC and Base are measures, so I did not include those in any aggregation. 

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Channel])), 1, 0 ) > 0,

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Customer])), 1, 0 ) > 0

),

0,

1

)

* IF (

OR (

MAX(Input[Brand]) = "RESIDUAL STOCK",

FIND ( "CENTRAL", UPPER (HASONEVALUE(Input[Brand])), 1, 0 ) > 0

 

The issue is around the MAX and HASNOVALUE Function, while it was a column it was an if condition, after changing to measue IF condition was not working, so I tried DISTINCT and HASNOVALUE but none of them seems to work.

Ah. Yeah, measures shouldn't need extra aggregations.

 

I think your measure could be simplified quite a bit. I'd suggest starting from something like this:

 

MeasureName =
VAR Channel = SELECTEDVALUE ( Input[Channel] )
VAR Customer = SELECTEDVALUE ( Input[Customer] )
VAR Brand = SELECTEDVALUE ( Input[Brand] )
RETURN
    IF (
        Channel = "All"
            || [NR/HL Country Base] = 0
            || CONTAINSSTRING ( Channel, "CENTRAL" )
            || CONTAINSSTRING ( Customer, "CENTRAL" )
            || Brand = "RESIDUAL STOCK"
            || CONTAINSSTRING ( Brand, "CENTRAL" )
            || ABS ( [NR/HL Channel Base] - [NR/HL Channel AC] ) > 500,
        0,
        1
    ) / 1000

 

Note that CONTAINSSTRING is not case-sensitive, so you don't need upper.

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.