Power BI stacked column chart

I need to create a stacked column chart where on the x axis it lists employee names.  The employee name could be in two different columns in my data set.  I would like the stacked column to show each order for each employee by price.  Below is an example of the dataset.

Emp1    Emp2    price   Order
Joe         Jim         100     11111
Jim         Jim         200     22222
Bill         Joe         200     33333
Bill                        100    44444

I would want the x axis to have Joe, Jim and Bill listed and each to have a stacked column by price
jnikodymAsked:
Who is Participating?
 
PortletPaulfreelancerCommented:
Then use a group by clause, like this:
select Emp1, [order], sum(price)
from (
      select Emp1, price, [order] from table1 where emp1 is not null
      union all
      select Emp2, price, [order] from table1 where emp2 is not null
      ) d
group by emp1, [order]
order by emp1, [order]

| Emp1 | order |     |
|------|-------|-----|
| Bill | 33333 | 200 |
| Bill | 44444 | 100 |
|  Jim | 11111 | 100 |
|  Jim | 22222 | 400 |
|  Joe | 11111 | 100 |
|  Joe | 33333 | 200 |

http://sqlfiddle.com/#!6/537a08/3

Open in new window

0
 
PortletPaulfreelancerCommented:
Does this produce the expected data for your graph?

CREATE TABLE Table1
    ([Emp1] varchar(4), [Emp2] varchar(4), [price] int, [Order] int)
;
    
INSERT INTO Table1
    ([Emp1], [Emp2], [price], [Order])
VALUES
    ('Joe', 'Jim', 100, 11111),
    ('Jim', 'Jim', 200, 22222),
    ('Bill', 'Joe', 200, 33333),
    ('Bill', NULL, 100, 44444)
;

**Query 1**:

select Emp1, price, [order] from table1 where emp1 is not null
union all
select Emp2, price, [order] from table1 where emp2 is not null
order by emp1, price


| Emp1 | price | order |
|------|-------|-------|
| Bill |   100 | 44444 |
| Bill |   200 | 33333 |
|  Jim |   100 | 11111 |
|  Jim |   200 | 22222 |
|  Jim |   200 | 22222 |
|  Joe |   100 | 11111 |
|  Joe |   200 | 33333 |

[1]: http://sqlfiddle.com/#!6/537a08/2

Open in new window

0
 
jnikodymAuthor Commented:
It’s close. In this example I would only want Jim listed once.
0
 
jnikodymAuthor Commented:
I'm sorry, i meant in this example Jim should only be listed twice.  Once for Order 11111 and once for order 22222
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.