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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

How to calculate the average size of size list text in Direct Query mode

In short, Now I have a text column like                     //maybe more than 3 size pairs

"24x24 36x36 64x80"

Now I have to calculate the average width (24 + 36 +64) / 3   

 

further, I need to calculate how many square in the above text. (2)

 

Notice: I use direct query mode now.          Use DAX or power query are both OK.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column as below to get it, please find the details in the attachment.

Average width = 
VAR _replace1 =
    SUBSTITUTE ( 'Table'[size_list], " ", "|" )
VAR SplitBySpace =
    PATHLENGTH ( _replace1 )
VAR _replace2 =
    SUBSTITUTE ( _replace1, "x", "|" )
VAR SplitBySpace2 =
    PATHLENGTH ( _replace2 )
VAR Mylen =
    LEN ( _replace2 )
VAR mytable =
    ADDCOLUMNS (
        GENERATESERIES ( 1, SplitBySpace2 ),
        "mylist", VALUE ( PATHITEM ( _replace2, [Value] ) )
    )
VAR Result =
    DIVIDE (
        SUMX ( FILTER ( mytable, MOD ( [Value], 2 ) = 1 ), [mylist] ),
        SplitBySpace,
        0
    )
RETURN
    Result

vyiruanmsft_0-1698722753027.png

Best Regards

View solution in original post

5 REPLIES 5
FreemanZ
Super User
Super User

hi @Anonymous 

do you have more sample data?

the digit could be extracted with LEFT, RIGHT functions with DAX and PQ. 

Anonymous
Not applicable

we can make it manually,

[size_list]

"12x23 20x20 30x30 512x512"

"1024x768 1920x1080"

"2080x3070 1x1 2x2 3x4 4x5 5x6 6x7 7x8"

like these

hi @Anonymous ,

 

you can try with Power Query. check what is attached. 

FreemanZ_0-1698387215702.png

 

Anonymous
Not applicable

The Table.SplitColumn is not supported in direct query mode.

Asamia_0-1698394900501.png

 

Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column as below to get it, please find the details in the attachment.

Average width = 
VAR _replace1 =
    SUBSTITUTE ( 'Table'[size_list], " ", "|" )
VAR SplitBySpace =
    PATHLENGTH ( _replace1 )
VAR _replace2 =
    SUBSTITUTE ( _replace1, "x", "|" )
VAR SplitBySpace2 =
    PATHLENGTH ( _replace2 )
VAR Mylen =
    LEN ( _replace2 )
VAR mytable =
    ADDCOLUMNS (
        GENERATESERIES ( 1, SplitBySpace2 ),
        "mylist", VALUE ( PATHITEM ( _replace2, [Value] ) )
    )
VAR Result =
    DIVIDE (
        SUMX ( FILTER ( mytable, MOD ( [Value], 2 ) = 1 ), [mylist] ),
        SplitBySpace,
        0
    )
RETURN
    Result

vyiruanmsft_0-1698722753027.png

Best Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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