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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
Ramagopal
Regular Visitor

DAX Formula for Stacked CHart

I need to make a stacked column chart where percentages are shown in the tooltips. I am having issues displaying percentages correctly. Data in excel shared

 

Ramagopal_0-1778221070679.png

 

% TVR by Promo =
VAR CurrentMonth = SELECTEDVALUE(New_Dash_Board[month])
VAR CurrentSpotType = SELECTEDVALUE(New_Dash_Board[Type])
VAR CurrentPromo = SELECTEDVALUE(New_Dash_Board[Promotional])

VAR Numerator =
    SUM(New_Dash_Board[sum(tvr)])

VAR Denominator =
    CALCULATE(
        SUM(New_Dash_Board[sum]),
        FILTER(
            ALL(New_Dash_Board),
            New_Dash_Board[month] = CurrentMonth &&
           New_Dash_Board[Type] = CurrentSpotType
        )
    )

RETURN
DIVIDE(Numerator, Denominator, 0)... Using this I am continuosly getting the denominator same as the numerator and percantage coming as 100%...
 
Can any one suggest me where I need to correct my logic
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Ramagopal ,

 

For this you need to use a measure to change the different levels of the scope try the following code:

 

% TVR by Promo =
		VAR CurrentSpotType = SELECTEDVALUE('New_Dash_Board'[Type])
		VAR CurrentSpotMother = SELECTEDVALUE('New_Dash_Board'[Mother])
		VAR CurrentPromo = SELECTEDVALUE('New_Dash_Board'[Promotional])

		VAR Numerator =
		SUM('New_Dash_Board'[sum(tvr)])

		VAR Denominator =
		SWITCH(
			TRUE(),
			ISINSCOPE(New_Dash_Board[Promotional]), CALCULATE(
				SUM('New_Dash_Board'[sum(tvr)]),
				REMOVEFILTERS(New_Dash_Board[Promotional]),
				New_Dash_Board[Type] = CurrentSpotType
			),

			ISINSCOPE(New_Dash_Board[Type]), CALCULATE(
				SUM('New_Dash_Board'[sum(tvr)]),
				REMOVEFILTERS(New_Dash_Board[Type]),
				New_Dash_Board[Mother] = CurrentSpotMother
			),
			ISINSCOPE(New_Dash_Board[Mother]), CALCULATE(
				SUM('New_Dash_Board'[sum(tvr)]),
				REMOVEFILTERS(New_Dash_Board[Mother])
			)
		)


		RETURN
			DIVIDE(
				Numerator,
				Denominator,
				0
			)

MFelix_0-1778230097396.png

 

An easier option is to use a visual calculation that way you only need to write the following code:

TVR % = DIVIDE([Total] ,CALCULATE([Total] ,COLLAPSE(ROWS,1 )))

 

Has you can see result is the same:

 

MFelix_0-1778230629423.png

 

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-visual-calculations-overview

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

4 REPLIES 4
V-yubandi-msft
Community Support
Community Support

Hi @Ramagopal ,

Could you let us know if your issue has been resolved or if you need any more information. We're here to help if you need further assistance.

 

Thank you.

V-yubandi-msft
Community Support
Community Support

Hi @Ramagopal ,

If you get a chance, please review the response shared by @MFelix , @krishnakanth240 and let us know if it aligns with your expectations. Should you need any additional details or clarification, feel free to let us know.

 

Thank you for your valuable input @krishnakanth240, @MFelix .

 

Regards,
Yugandhar.

krishnakanth240
Resident Rockstar
Resident Rockstar

Hi @Ramagopal 

Can you try this measure

 

% TVR by Promo =

VAR CurrentMonth = SELECTEDVALUE(New_Dash_Board[month])

 

VAR CurrentSpotType = SELECTEDVALUE(New_Dash_Board[Type])

 

VAR Numerator = SUM(New_Dash_Board[sum(tvr)])

 

VAR Denominator = CALCULATE(

SUM(New_Dash_Board[sum(tvr)]),

FILTER(ALLEXCEPT(New_Dash_Board,

New_Dash_Board[month], New_Dash_Board[Type]),

New_Dash_Board[month] = CurrentMonth && New_Dash_Board[Type] = CurrentSpotType))

RETURN

DIVIDE(Numerator, Denominator, 0)

MFelix
Super User
Super User

Hi @Ramagopal ,

 

For this you need to use a measure to change the different levels of the scope try the following code:

 

% TVR by Promo =
		VAR CurrentSpotType = SELECTEDVALUE('New_Dash_Board'[Type])
		VAR CurrentSpotMother = SELECTEDVALUE('New_Dash_Board'[Mother])
		VAR CurrentPromo = SELECTEDVALUE('New_Dash_Board'[Promotional])

		VAR Numerator =
		SUM('New_Dash_Board'[sum(tvr)])

		VAR Denominator =
		SWITCH(
			TRUE(),
			ISINSCOPE(New_Dash_Board[Promotional]), CALCULATE(
				SUM('New_Dash_Board'[sum(tvr)]),
				REMOVEFILTERS(New_Dash_Board[Promotional]),
				New_Dash_Board[Type] = CurrentSpotType
			),

			ISINSCOPE(New_Dash_Board[Type]), CALCULATE(
				SUM('New_Dash_Board'[sum(tvr)]),
				REMOVEFILTERS(New_Dash_Board[Type]),
				New_Dash_Board[Mother] = CurrentSpotMother
			),
			ISINSCOPE(New_Dash_Board[Mother]), CALCULATE(
				SUM('New_Dash_Board'[sum(tvr)]),
				REMOVEFILTERS(New_Dash_Board[Mother])
			)
		)


		RETURN
			DIVIDE(
				Numerator,
				Denominator,
				0
			)

MFelix_0-1778230097396.png

 

An easier option is to use a visual calculation that way you only need to write the following code:

TVR % = DIVIDE([Total] ,CALCULATE([Total] ,COLLAPSE(ROWS,1 )))

 

Has you can see result is the same:

 

MFelix_0-1778230629423.png

 

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-visual-calculations-overview

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.