'How to add category to column in Power BI?
I have data similar to this format:
customerName | Type of Sale | Sales Amount | Unit Purchased
-------------------------------------------------------------------
A | Online | 1500 | 4
B | Offline | 2000 | 5
C | Online | 3000 | 4
D | Offline | 4000 | 4
and I want data in following format in Power BI in Matrix Format
Metric | Sales Amount | Units Purchased
-----------------------------------------------------------
Customer Name | Online | Offline | Online | Offline
-----------------------------------------------------------
A | 15000 | 0 | 4 | 0
B | 0 | 2000 | 0 | 5
Solution 1:[1]
We can achieve this kind of visualization, but this needs some steps (more effort, Lower performance compared to the standard design.)
First we need an additional table with lables "Sales Amount" and "Units Purchased". Relationship many to many.
Add additional measures:
Offline =
var sale = CALCULATE(sum('Sales'[Sales Amount]), FILTER(ALL('Sales'[Type of Sale]), 'Sales'[Type of Sale] = "Offline"))
var purch = CALCULATE(sum('Sales'[Unit Purchased]), FILTER(ALL('Sales'[Type of Sale]), 'Sales'[Type of Sale] = "Offline"))
return
if (SELECTEDVALUE('Lables'[LableName]) = "Purchase",purch,sale)
Online =
var sale = CALCULATE(sum('Sales'[Sales Amount]), FILTER(ALL('Sales'[Type of Sale]), 'Sales'[Type of Sale] = "Online"))
var purch = CALCULATE(sum('Sales'[Unit Purchased]), FILTER(ALL('Sales'[Type of Sale]), 'Sales'[Type of Sale] = "Online"))
return
if (SELECTEDVALUE('Lables'[LableName]) = "Sales Amount", sale,purch)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | msta42a |



