cancel
Showing results for
Did you mean:
Member

## How to sum values horizontally in a table?

Hello.

I have sales data for number of products sold per staff member that looks like this, with the totals being calculated vertically, how can it be calculated horizontally as well?

My data:

Name         Gloves            Hats            Scarfs
James          3                      2                 4
Jane             1                      3                2
Chris            0                      1                1

Power Bi adds the total as summing vertically:

Total          4                      6              7

How can I make it look like this?

Name         Gloves            Hats            Scarfs           Total
James          3                      2                 4                     10
Jane             1                      3                2                       6
Chris             0                      1                1                       2

I guess I have to create a measure?  I don't want the Total vertically, just horizontally.

Many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Senior Member

## Re: How to sum values horizontally in a table?

You can go to Format pane of your table, and there should be an option for grand total that you can turn it off to remove Total. As for displays 0, you can write the following:

Sales Total =

VAR temp = SUMX(Sales, Sales[Hat] + Sales[Scarf] + Sales[Gloves])

RETURN IF(temp = BLANK(), 0, temp)

5 REPLIES 5
Senior Member

## Re: How to sum values horizontally in a table?

You can create a measure like this:

Total = SUMX(Sales, Sales[Gloves] + Sales[Hats] + Sales[Scarfs])

Then simple drag it to your table

Member

## Re: How to sum values horizontally in a table?

Thanks very much for this, @NickNg278.  Let me try it out and see.

Super User

## Re: How to sum values horizontally in a table?

Hi,

Your data is not well structures.  It should ideally be a 3 column dataset - Name, Item and Value.  The item column should have Gloves, Scarfs and Hats.  To do so, in the Query Editor window, right click on the first column and select "Unpivot other columns".  Click on Close and Load.  Now build your visual.

Member

## Re: How to sum values horizontally in a table?

Hello @NickNg278.

Your measure worked great, thank you!

I used it to make this table:

 Month Hat Scarf Gloves SalesTotal March 1 6 4 11 Total 1 6 4 11

In the above, SalesTotal is your measure, and works great, but Total is calculated by Power Bi - how do I remove it?

Also, how can SalesTotal be edited so that if some products have no sales, it displays 0 instead of being blank?

Many thanks.

Senior Member

## Re: How to sum values horizontally in a table?

You can go to Format pane of your table, and there should be an option for grand total that you can turn it off to remove Total. As for displays 0, you can write the following:

Sales Total =

VAR temp = SUMX(Sales, Sales[Hat] + Sales[Scarf] + Sales[Gloves])

RETURN IF(temp = BLANK(), 0, temp)