Forum Discussion
Create a slicer from a measure
- 3 years ago
It seems like you want to create a calculated column for GP% (Gross Profit Percentage) and then create a slicer based on the range of GP%. However, Power BI doesn't allow a slicer directly from a measure.
1. Join the 3 tables based on Item Code.
2. Create a new calculated column for GP%, the formula should be something like: `(Sales[Unit Price] - LAST COSTS[Last PO Cost]) / Sales[Unit Price]`
3. Create a new column "GP% Range", which will be used to determine the range of GP%.
Here are the DAX formulas:
1. Join tables:
If they aren't joined already, you can create relationships between these tables in Power BI based on Item Code. This isn't done with DAX, but in the modeling section of Power BI Desktop.
2. GP%:
```DAX
GP% = (Sales[Unit Price] - 'LAST COSTS'[Last PO Cost]) / Sales[Unit Price]
```3. GP% Range:
```DAX
GP% Range =
SWITCH (
TRUE(),
'Sales'[GP%] <= 0.02, "2% and lower",
'Sales'[GP%] > 0.02 && 'Sales'[GP%] <= 0.05, "2%-5%",
'Sales'[GP%] > 0.05, "5% and higher",
"Other"
)
```This new "GP% Range" column can be used to create the slicer, and this will filter your data according to the range of GP% when you select different buttons in the slicer.
Please be aware that creating calculated columns, especially those using SWITCH or other similar functions, could have a performance impact on your Power BI report, especially if you have a large volume of data. As always, make sure to test the performance and adjust as necessary.
Based on the data you provided the slicer contains only the current value :
I am attaching the PBIX file.
It seems like you want to create a calculated column for GP% (Gross Profit Percentage) and then create a slicer based on the range of GP%. However, Power BI doesn't allow a slicer directly from a measure.
1. Join the 3 tables based on Item Code.
2. Create a new calculated column for GP%, the formula should be something like: `(Sales[Unit Price] - LAST COSTS[Last PO Cost]) / Sales[Unit Price]`
3. Create a new column "GP% Range", which will be used to determine the range of GP%.
Here are the DAX formulas:
1. Join tables:
If they aren't joined already, you can create relationships between these tables in Power BI based on Item Code. This isn't done with DAX, but in the modeling section of Power BI Desktop.
2. GP%:
```DAX
GP% = (Sales[Unit Price] - 'LAST COSTS'[Last PO Cost]) / Sales[Unit Price]
```
3. GP% Range:
```DAX
GP% Range =
SWITCH (
TRUE(),
'Sales'[GP%] <= 0.02, "2% and lower",
'Sales'[GP%] > 0.02 && 'Sales'[GP%] <= 0.05, "2%-5%",
'Sales'[GP%] > 0.05, "5% and higher",
"Other"
)
```
This new "GP% Range" column can be used to create the slicer, and this will filter your data according to the range of GP% when you select different buttons in the slicer.
Please be aware that creating calculated columns, especially those using SWITCH or other similar functions, could have a performance impact on your Power BI report, especially if you have a large volume of data. As always, make sure to test the performance and adjust as necessary.
Based on the data you provided the slicer contains only the current value :
I am attaching the PBIX file.