cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chandrashekarc
Helper III
Helper III

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

@chandrashekarc 

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

@chandrashekarc 

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. 

 

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

@chandrashekarc 

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. 

 

 

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

@chandrashekarc 

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 @

 



New Power BI Features
Datamarts: https://youtu.be/8tskWsJTEpg
Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin !! Proud to be a Super User!
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
!! Subscribe to my youtube Channel !!

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
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors