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
monojchakrab
Resolver III
Resolver III

MID function as a variable

Total shipped qty = 
SUMX('Amazon YTD','Amazon YTD'[Shipped Quantity]*RELATED('summary table'[MPU]))

Hi All,

 

I have a table which have got the product name, which includes the Pack size as part of the text string :

 

monojchakrab_0-1659346800919.png

I have inserted a column with the MID function which extract the pack size from the string.

But now I am trying to use the MID function in a variable, so that I can multiple the shipped qty with the pack size (Called "MPU" here) and get the total qty :

Total shipped qty =
SUMX('Amazon YTD','Amazon YTD'[Shipped Quantity]*RELATED('summary table'[MPU]))
But when I am trying to add the MID function in a variable, it is not allowing me to choose a column on which to perform the MID search.
Can the MID function be used a quasi-iterator in a measure, instead of in a calculated column only?
Thanks for the help in anticipation
regds.,
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@monojchakrab , First bring this as a column -RELATED('summary table'[MPU]) 

and then try MID

View solution in original post

v-stephen-msft
Community Support
Community Support

Hi @monojchakrab ,

 

You want to extract the number from the strings in Size column, right?

It is recommended that you use the LEFT() function to get the number.

Measure = LEFT(MAX('Table'[SIZE]),LEN(MAX('Table'[SIZE]))-6)

 

vstephenmsft_0-1661937853922.png

You will find that the numbers you propose are text types, you can modify the type manually, or you can add VALUE() to change the number type.

vstephenmsft_1-1661937965550.png

 

 

Best Regards,

Stephen Tao

 

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
v-stephen-msft
Community Support
Community Support

Hi @monojchakrab ,

 

You want to extract the number from the strings in Size column, right?

It is recommended that you use the LEFT() function to get the number.

Measure = LEFT(MAX('Table'[SIZE]),LEN(MAX('Table'[SIZE]))-6)

 

vstephenmsft_0-1661937853922.png

You will find that the numbers you propose are text types, you can modify the type manually, or you can add VALUE() to change the number type.

vstephenmsft_1-1661937965550.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

monojchakrab
Resolver III
Resolver III

Total shipped qty = 
VAR _Title= SELECTCOLUMNS('Amazon YTD',"Title",'Amazon YTD'[Title]) --chooses to colum of [Title] to apply the MID function to; this is from the same table so did not have to use the Related function
VAR _SearchPack = SEARCH("of",_Title,,0)+3 --In order to find the starting position for the MID function
VAR _MPU = value(MID(_Title,_SearchPack,1)) --extracts the pack size and converts to numeric value
return 
SUMX('Amazon YTD','Amazon YTD'[Shipped Quantity]*_MPU) --iterates over [shipped qty] and multiplies by the pack size to arrive at the volume

@amitchandak - Amit, I rewrote the code, and did not use the RELATED function as I am pulling the String column ([Title]) fromt the same table.

But this one is returning an error as follows :

monojchakrab_0-1659351059472.png

Any reason why and how to get out of it?

Thanks

amitchandak
Super User
Super User

@monojchakrab , First bring this as a column -RELATED('summary table'[MPU]) 

and then try MID

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.