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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ianwuk
Helper III
Helper III

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

@ianwuk,

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)

 

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

You can create a measure like this:

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

Then simple drag it to your table

Hello @Anonymous.

 

Your measure worked great, thank you!

I used it to make this table:

MonthHatScarfGlovesSalesTotal
March16411
Total16411


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.

Anonymous
Not applicable

@ianwuk,

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)

 

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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