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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Expressions that yield variant data-type cannot be used (multiply with constant value)

Hello,

 

Could you help with DAX for below situation.

IF(OR(All_Data_View[supplier_name]="ABC",All_Data_View[supplier_name]="XYZ"),
SUMX(All_Data_View,All_Data_View[part_qty])*(12))
 
Where 12 is constant value.
 
Thanks,
CS

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous 

Make sure the datatypes are setup correctly in the power query editor. (QTY as wholenumber)

With your test data the following measure worked for me:

Column =
IF (
    All_Data_View[Shipping Site] = "XYZ",
    All_Data_View[Part Qty] * 15.2,
    IF (
        All_Data_View[Shipping Site] = "ABC"
            && All_Data_View[Part Qty] < 100,
        All_Data_View[Part Qty] * 10,
        50
    )
)

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

@Anonymous 

If this is a measure this is not gonna work regardless. The IF statement is not iterating the table and you should use a filter.

From what I can tell this code should result in the same output:

Measure =
CALCULATE (
    SUM ( All_Data_View[part_qty] ) * 12,
    All_Data_View[supplier_name] = "ABC"
        || All_Data_View[supplier_name] = "XYZ"
)

 

Hope this helps.

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

 

Anonymous
Not applicable

Hi,

Thanks for your reply!

 

I am trying to calculate transaction fee in single new column using "nested if" for set of data value, and this among one condition.

If there any other way to get this condition worked along with others in same column.

 

Regards,

CS

 

Anonymous
Not applicable

@Anonymous 

I'm still not a 100% sure if you are doing this as a measure or as a calculated column.

In case of a measure try and nest the if statement in the sumx like this:

SUMX ( All_Data_View, IF ( All_Data_View[supplier_name]="ABC" || All_Data_View[supplier_name]="XYZ", All_Data_View[part_qty] *12, <alternative> ) )

Incase of a column it will always iterate and should work like this:

IF ( All_Data_View[supplier_name]="ABC" || All_Data_View[supplier_name]="XYZ", All_Data_View[part_qty] *12, <alternative> ) 

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

 

 

Anonymous
Not applicable

Hi Joren, Thanks!

I am doing this in new column, and still get this error "Expressions that yield variant data-type cannot be used to define calculated columns"

 

Regards,

CS

 

Anonymous
Not applicable

@Anonymous 

Make sure the datatypes are setup correctly in the power query editor. (QTY as wholenumber)

With your test data the following measure worked for me:

Column =
IF (
    All_Data_View[Shipping Site] = "XYZ",
    All_Data_View[Part Qty] * 15.2,
    IF (
        All_Data_View[Shipping Site] = "ABC"
            && All_Data_View[Part Qty] < 100,
        All_Data_View[Part Qty] * 10,
        50
    )
)

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

 

Can you share sample data and sample output. Mark me @

 

Anonymous
Not applicable

Hi Amitchandak,

 

Here is the sample data.

And i am looking at output as:

If shipping site=XYZ, then (Part Qty)*15.12

else if shipping site=ABC and (Part Qty)<100, then  (Part Qty)*10 else 50

 

Claim N°Claim statusPart N°Part descriptionPart QtyExtended Item valueShipping SiteTransaction_Fee
1CLOSED836308SPS-KYBD BL W/PT STK 14-FR25733.5XYZ237.5
2CLOSED826630SPS-KEYBOARD BACKLIT W/POINT STICK FR20583XYZ190
3CLOSED929985TOP COVER, W/KB PRVCY EURO2216.5ABC19
4CLOSEDL17971SPS-KYBD SR BL 15W GR129.02ABC9.5
5CLOSED922749KB, BASE TR CP BL CLLB SWIS22169.32ABC19
6CLOSED934597Assy, Stand, Yoshi10.01XYZ9.5
7CLOSED901771P/S,SFF,180W ENTL17,85% EFF HV,12V 1OT20293.2XYZ190
8CLOSED848311SPS-KYBD TP BL BEL 30897.3ABC285
9CLOSED929985TOP COVER, W/KB PRVCY EURO1108.25XYZ9.5
10CLOSEDL15540SPS-KYBD SR BL 14W EUROA5127.04XYZ9.5

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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