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
BrendaA
Regular Visitor

Measure: sumx with summarize

I  have a table with following fields

2019-09-23 15_04_20-Example PowerBi - Power BI Desktop.png

 

 

 

 

 

What I would like to calculate is the additional online sales in case the shop would sell the same % online per product as all shops together. I was able to generate a summarized table that calculates the "additional online sales" 

 

SummarizedTabel =
ADDCOLUMNS (
    ADDCOLUMNS (
        ADDCOLUMNS (
            SUMMARIZE (
                Sales;
                Sales[Product];
                Sales[Region];
                Sales[Sold by];
                "Sales"; SUM ( Sales[Sales] );
                "Sales Online"; CALCULATE (
                    SUM ( Sales[Sales] );
                    ALLSELECTED ( Sales[Sold by] );
                    Sales[Sold by] = "Online"
                );
                "Sales Store"; CALCULATE (
                    SUM ( Sales[Sales] );
                    ALLSELECTED ( Sales[Sold by] );
                    Sales[Sold by] = "Store"
                );
                "Total shops Online"; CALCULATE (
                    SUM ( Sales[Sales] );
                    ALLSELECTED ( Sales[Sold by]; Sales[Region] );
                    Sales[Sold by] = "Online"
                );
                "Total shops store"; CALCULATE (
                    SUM ( Sales[Sales] );
                    ALLSELECTED ( Sales[Sold by]; Sales[Region] );
                    Sales[Sold by] = "Store"
                )
            );
            "Total shops online vs total"; [Total shops Online] / ( [Total shops Online] + [Total shops store] );
            "Selected shop online vs total"; [Sales Online] / ( [Sales Online] + [Sales Store] )
        );
        "diff total shops vs selected shop"; [Total shops online vs total] - [Selected shop online vs total]
    );
    "additional sales online"; IF (
        [diff total shops vs selected shop] < 0;
        0;
        [Sales] * [diff total shops vs selected shop]
    )
)

But as the original data has more then 1 million rows and I need to apply quite a lot of filters I could like to include the calculation of additional online sales in a measure so that all the report filters get applied (filters based on linked tables). I tried to include the code above in a measure

 

Addiontional sales =
SUMX (
    ADDCOLUMNS (
        ADDCOLUMNS (
            ADDCOLUMNS (
                SUMMARIZE (
                    Sales;
                    Sales[Product];
                    Sales[Region];
                    Sales[Sold by];
                    "Sales"; SUM ( Sales[Sales] );
                    "Sales Online"; CALCULATE (
                        SUM ( Sales[Sales] );
                        ALLSELECTED ( Sales[Sold by] );
                        Sales[Sold by] = "Online"
                    );
                    "Sales Store"; CALCULATE (
                        SUM ( Sales[Sales] );
                        ALLSELECTED ( Sales[Sold by] );
                        Sales[Sold by] = "Store"
                    );
                    "Total shops Online"; CALCULATE (
                        SUM ( Sales[Sales] );
                        ALLSELECTED ( Sales[Sold by]; Sales[Region] );
                        Sales[Sold by] = "Online"
                    );
                    "Total shops store"; CALCULATE (
                        SUM ( Sales[Sales] );
                        ALLSELECTED ( Sales[Sold by]; Sales[Region] );
                        Sales[Sold by] = "Store"
                    )
                );
                "Total shops online vs total"; [Total shops Online] / ( [Total shops Online] + [Total shops store] );
                "Selected shop online vs total"; [Sales Online] / ( [Sales Online] + [Sales Store] )
            );
            "diff total shops vs selected shop"; [Total shops online vs total] - [Selected shop online vs total]
        );
        "additional sales online"; IF (
            [diff total shops vs selected shop] < 0;
            0;
            [Sales] * [diff total shops vs selected shop]
        )
    );
    [additional sales online]
)

But when I look at the results it is not what I want to see. The total is correct but I am not able to see the additional sales per product en per region.

2019-09-23 15_22_25-Example PowerBi - Power BI Desktop.png

 

 

 

 

 

 

 

 

How can I solve this? Is there another way to get this solved instead of using summarize?

I am using Power BI for just a few weeks, so I would be surprised if there is a much easier way to calculate the additional online sales.

 

Thanks in advance for your help on this one...

 

Kind regards

Brenda

1 REPLY 1
Anonymous
Not applicable

GOOD PIECE OF ADVICE: Do not use SUMMARIZE for obtaining figures. Use this function ONLY for getting the combinations of values against which you want to calculate numbers. Instead, use the combination of SUMMARIZE/ADDCOLUMNS.

SUMMARIZE is a very complex function that has many bugs into the bargain. Complex in this context means it's very often doing something different from what you think it should.

If you want to know why you shouldn't do that please refer to the articles on SUMMARIZE at www.sqlbi.com.

Best
D.

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.

Top Solution Authors