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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymus_18
Frequent Visitor

Summarize

I have provided the sample table.I need to summarize the numbers there is same sports rows with places interchanged.so I need to add them in a single row(teqball,basketball |60).

sportsnumber
teqball6
teqball,basketball29
basketball15
soccer65
soccer,teqball50
basketball,teqball31
1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @Anonymus_18 

You can refer to the follwing calculated table.

Table 2 =
VAR add1 =
    ADDCOLUMNS (
        'Table',
        "Type1",
            VAR a =
                SEARCH ( ",", 'Table'[sports], 1, BLANK () )
            RETURN
                IF ( a <> BLANK (), LEFT ( [sports], a - 1 ), [sports] )
    )
VAR add2 =
    ADDCOLUMNS (
        add1,
        "Type2",
            VAR a =
                SEARCH ( ",", 'Table'[sports], 1, BLANK () )
            VAR b =
                IF ( a <> BLANK (), MID ( [sports], a + 1, LEN ( [sports] ) - a ), [sports] )
            RETURN
                IF ( b = [Type1], BLANK (), b )
    )
VAR add3 =
    ADDCOLUMNS (
        add2,
        "Index",
            IF (
                [Type2] = BLANK (),
                1,
                RANKX (
                    FILTER (
                        'Table',
                        CONTAINSSTRING ( [sports], EARLIER ( [Type1] ) )
                            && CONTAINSSTRING ( [sports], EARLIER ( [Type2] ) )
                    ),
                    [number],
                    ,
                    ASC
                )
            ),
        "Sum",
            IF (
                [Type2] = BLANK (),
                [number],
                CALCULATE (
                    SUM ( 'Table'[number] ),
                    FILTER (
                        'Table',
                        CONTAINSSTRING ( [sports], EARLIER ( [Type1] ) )
                            && CONTAINSSTRING ( [sports], EARLIER ( [Type2] ) )
                    )
                )
            )
    )
RETURN
    SUMMARIZE ( FILTER ( add3, [Index] = 1 ), [sports], [Sum] )

Output

vxinruzhumsft_0-1693967479146.png

 

Best Regards!

Yolo Zhu

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

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This should ideally be done in the Query Editor.  If you OK with my approach, then post back.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-xinruzhu-msft
Community Support
Community Support

Hi @Anonymus_18 

You can refer to the follwing calculated table.

Table 2 =
VAR add1 =
    ADDCOLUMNS (
        'Table',
        "Type1",
            VAR a =
                SEARCH ( ",", 'Table'[sports], 1, BLANK () )
            RETURN
                IF ( a <> BLANK (), LEFT ( [sports], a - 1 ), [sports] )
    )
VAR add2 =
    ADDCOLUMNS (
        add1,
        "Type2",
            VAR a =
                SEARCH ( ",", 'Table'[sports], 1, BLANK () )
            VAR b =
                IF ( a <> BLANK (), MID ( [sports], a + 1, LEN ( [sports] ) - a ), [sports] )
            RETURN
                IF ( b = [Type1], BLANK (), b )
    )
VAR add3 =
    ADDCOLUMNS (
        add2,
        "Index",
            IF (
                [Type2] = BLANK (),
                1,
                RANKX (
                    FILTER (
                        'Table',
                        CONTAINSSTRING ( [sports], EARLIER ( [Type1] ) )
                            && CONTAINSSTRING ( [sports], EARLIER ( [Type2] ) )
                    ),
                    [number],
                    ,
                    ASC
                )
            ),
        "Sum",
            IF (
                [Type2] = BLANK (),
                [number],
                CALCULATE (
                    SUM ( 'Table'[number] ),
                    FILTER (
                        'Table',
                        CONTAINSSTRING ( [sports], EARLIER ( [Type1] ) )
                            && CONTAINSSTRING ( [sports], EARLIER ( [Type2] ) )
                    )
                )
            )
    )
RETURN
    SUMMARIZE ( FILTER ( add3, [Index] = 1 ), [sports], [Sum] )

Output

vxinruzhumsft_0-1693967479146.png

 

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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