Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply

How to create a single measure that dynamically switches between showing a number or a percentage..

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.

BarbaraYanChen_0-1735664234445.png 

BarbaraYanChen_1-1735664420908.png

 

Thanks,

 

Barbara

1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

@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

sanalytics_0-1735723945874.png

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

sanalytics_1-1735724118907.png

Attached is the pbix file

https://we.tl/t-pCBQoFQDhz

 

Hope, it will help.

 

Regards

sanalytics

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

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.

sanalytics
Super User
Super User

@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

sanalytics_0-1735723945874.png

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

sanalytics_1-1735724118907.png

Attached is the pbix file

https://we.tl/t-pCBQoFQDhz

 

Hope, it will help.

 

Regards

sanalytics

Poojara_D12
Super User
Super User

Hi @BarbaraYanChen 

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 

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 - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
lbendlin
Super User
Super User

You are trying to do too much.  Use separate columns.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.