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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
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
PortletPaulEE Topic AdvisorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
powerBI

From novice to tech pro — start learning today.