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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not applicable

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

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors