Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello,
I am making a line chart to show MoM trending in Power BI. I want to create a single measure that dynamically switches between showing a number or a percentage on the slicer selection.
Data see below screenshot: I have two columns in the dataset, one is "Value Only" with number type, and the other one is "Pct Only" with percentage type.
Goal see below screenshot: I want to create a measure that can swith between number and percentage types
FYI: it can't be text type as the value will be used for calculation (sum) in aggreated level as a total.
Thanks,
Barbara
Solved! Go to Solution.
@BarbaraYanChen
Easiest way to create a separate disconneted table for slicer and create a combined measure for this.
Combined Measure =
IF(
SELECTEDVALUE( SlicerTable[Sort] )= 1,
[MomValue],
IF(
SELECTEDVALUE( SlicerTable[Sort] ) = 2,
[MomPct],[MomValue]
) )
For Percntage formatting use measure's Dynamic format option and use below measure
IF(
SELECTEDVALUE( SlicerTable[Sort] )= 1,
"#,##0",
IF(
SELECTEDVALUE( SlicerTable[Sort] ) =2,
"0%","#,##0"
) )
Below screenshot
But, if you want to dare to see your screenshot result then create calculated table and use below code ( ideal way to create this table in Power query by simply unpivoting).
Sctsht =
VAR _1 =
SUMMARIZE( 'Table','Table'[Month] )
VAR _2 =
UNION(
ADDCOLUMNS(
_1,"Value and Pct",[MomValue],
"Tag","MomValue","Sort",1,"MonthSort",IF( 'Table'[Month] = "JAN",1, IF( 'Table'[Month] = "FEB",2 ) )
),
ADDCOLUMNS(
_1,"Value and Pct",[MomPct],"Tag","MomPct","Sort",2,"MonthSort",IF( 'Table'[Month] = "JAN",1, IF( 'Table'[Month] = "FEB",2 ) )
) )
RETURN
_2
For fomatting use same code.
IF(
SELECTEDVALUE( Sctsht[Tag] )= "MomValue",
"#,##0",
IF(
SELECTEDVALUE( Sctsht[Tag] ) ="MomPct",
"0%","#,##0"
) )
Below screenshot
Attached is the pbix file
Hope, it will help.
Regards
sanalytics
Create separate measures, one to show the value and one to show the %, and set the appropriate format strings. Create a field parameter, add those 2 measures to it and add a slicer to the page. Use the field parameter in your visual instead of the individual measures and the user will be able to switch which is displayed by using the slicer.
@BarbaraYanChen
Easiest way to create a separate disconneted table for slicer and create a combined measure for this.
Combined Measure =
IF(
SELECTEDVALUE( SlicerTable[Sort] )= 1,
[MomValue],
IF(
SELECTEDVALUE( SlicerTable[Sort] ) = 2,
[MomPct],[MomValue]
) )
For Percntage formatting use measure's Dynamic format option and use below measure
IF(
SELECTEDVALUE( SlicerTable[Sort] )= 1,
"#,##0",
IF(
SELECTEDVALUE( SlicerTable[Sort] ) =2,
"0%","#,##0"
) )
Below screenshot
But, if you want to dare to see your screenshot result then create calculated table and use below code ( ideal way to create this table in Power query by simply unpivoting).
Sctsht =
VAR _1 =
SUMMARIZE( 'Table','Table'[Month] )
VAR _2 =
UNION(
ADDCOLUMNS(
_1,"Value and Pct",[MomValue],
"Tag","MomValue","Sort",1,"MonthSort",IF( 'Table'[Month] = "JAN",1, IF( 'Table'[Month] = "FEB",2 ) )
),
ADDCOLUMNS(
_1,"Value and Pct",[MomPct],"Tag","MomPct","Sort",2,"MonthSort",IF( 'Table'[Month] = "JAN",1, IF( 'Table'[Month] = "FEB",2 ) )
) )
RETURN
_2
For fomatting use same code.
IF(
SELECTEDVALUE( Sctsht[Tag] )= "MomValue",
"#,##0",
IF(
SELECTEDVALUE( Sctsht[Tag] ) ="MomPct",
"0%","#,##0"
) )
Below screenshot
Attached is the pbix file
Hope, it will help.
Regards
sanalytics
Create a Slicer Table: Add a new table with options like "Show Value" and "Show Percentage":
SwitchTable = DATATABLE("Selection", STRING, {{"Show Value"}, {"Show Percentage"}})
Create a Dynamic Measure:
DynamicMeasure =
SWITCH(
SELECTEDVALUE(SwitchTable[Selection], "Show Value"),
"Show Value", SUM('YourTable'[Value Only]),
"Show Percentage", SUM('YourTable'[Pct Only])
)
Add a Slicer: Use SwitchTable[Selection] as a slicer on the report.
Use the Measure: Add DynamicMeasure to your line chart.
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
You are trying to do too much. Use separate columns.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
8 |