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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
amila
New Member

Percent of Column Total in Line Chart as a Part of Switch Formula

Hi Everyone,

 

I am quite new to Power BI so apologies if this is an easy one, or if it has already been answered. 

I have the below data structure containing Patient IDs with the information about their status regarding the treatment in question:

 

 INDENTIFIERSTATUS
411147Completed
411292Completed
413951Dropped out
414301Dropped Out
411147Dropped out
413951In progress
411292In progress
411581In progress
411671In progress
414321Not Initiated
411147Not Initiated
411581Not Initiated

 

I am trying to create a line chart with the possibilty to switch between two different views:

1) COUNT: showing the count of subjects for each of these statuses over time as a separate line

2) PERCENT: showing each status as a percentage of the total, also over time

 

So far, I have created the following two measures:

 

CountID= DISTINCTCOUNT(Table[IDENTIFIER])

PercentID = ?

 

Then I created a new table to use as a slicer, changing the view between COUNT and PERCENT with the following formula:

 

Switch = SWITCH([Selected TableParameter],1,Table[CountID],2,Table[PercentID],BLANK(),[CountID])

 

Everything works fine, except for the percentage formula. I have tried several options using DIVIDE, but nothing worked for me. I also tried to select "percent value of total" in the Visualizations section, but that just gave me simple 25% for each of the values. I was wondering if someone could help me figure what formula could be used to calculate the number of each of the STATUS values over time as percentage of total.

 

Thanks in advance!

 

Amila

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Should be something like:

 

Measure = DIVIDE(COUNTROWS(DISTINCT('Table3')),COUNTROWS(DISTINCT(ALL(Table3))),0)

The first COUNTROWS should be filtered according to the context. The second COUNTROWS removes all context and makes sure that you get all off the patients.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @amila,

 

Could you please mark the proper answers as solutions please?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Community Champion
Community Champion

Should be something like:

 

Measure = DIVIDE(COUNTROWS(DISTINCT('Table3')),COUNTROWS(DISTINCT(ALL(Table3))),0)

The first COUNTROWS should be filtered according to the context. The second COUNTROWS removes all context and makes sure that you get all off the patients.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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