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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ghdunn
Helper III
Helper III

Stacked Bar Waterfall - problems with Measures and Calculated Columns

I would like to create a Stacked Bar Waterfall.

 

I can spoof a simple version in this way:

Month Name Hard Coded Count

1 JanBob1
1 JanFred1
1 JanMary1
4 FebBob1
4 FebFred1
4 FebAnne1
3 LeaversMary1
2 JoinersAnn1
3 Leavers1. Invisible3
2 Joiners1. Invisible3

 

Which allows me to create this 'spoof' because I have turned the 'invisible' value white.

 

SpoofStackedBar.PNG

However, this is hard coding the value for the 'invisible' value.

 

If I wanted the count to be dynamic, then I can calculate the invisible value in M Query by using Group:

 

 #"Grouped Rows" = Table.Group(#"Changed Type", {"Month"}, {{"NewCount", each Table.RowCount(_), type number}})

 

I then bring that value for Jan and Feb into another step that generates the value for invisible...so far, so good.

 

HOWEVER....this only works for the relatively simply dataset I have.  

 

If I wanted to get smarter, and have a way of calculating the 'invisible' value even if the data is being filtered in the vizualisation as follows:

 

Month Name Type

1 JanBobPermanent
1 JanFredTemp
1 JanMaryPermanent
4 FebBobPermanent
4 FebFredTemp
4 FebAnnePermanent
3 LeaversMaryPermanent
2 JoinersAnnPermanent
3 Leavers1. Invisiblex
2 Joiners1. Invisiblex

 

I thought I could then use Measures to calculate how many people were in each month:

 

Jan = CALCULATE(COUNTROWS('Table'),'Table'[Month]="Jan")
Feb = CALCULATE(COUNTROWS('Table'),'Table'[Month]="Feb")

 

and then bring those measures back into the table using a calculate column to calculate the count

 

Generated Count= switch(true(),'Table'[Month]="Joiners" && 'Table[Type]= "x",[Jan],'Table'[Month]="Leavers" && 'Table[Type]= "x",[Feb],1)
 
Then that would generate a table:
 
Month Name Type Generated Count
1 JanBobPermanent1
1 JanFredTemp1
1 JanMaryPermanent1
4 FebBobPermanent1
4 FebFredTemp1
4 FebAnnePermanent1
3 LeaversMaryPermanent1
2 JoinersAnnPermanent1
3 Leavers1. Invisiblex3
2 Joiners1. Invisiblex3
 

Which would be filterable in the vizualization :

 

FilterStackedBar.PNG

So when I remove 'Temporary' from the filter, it dynamically re-calculates the invisible values for Jan and Feb.

 

But the combination of Measures and Calculated column doesn't seem to work.

 

If anyone could put me on the right track?

14 REPLIES 14
sturlaws
Resident Rockstar
Resident Rockstar

Hi, @ghdunn 

 

As you have experienced, calculated columns does not recalculate on any filter or slicer input. If you want this kind of dynamic behaviour, you will have to do it all by measures.

 

Could you provide a relevant sample data set, without any hardcoding?

 

Cheers,
Sturla

Hi Sturla,

 

Thanks for responding.

 

I think that is a simple sample data set in the OP - I don't think it needs to be any more complicated than that.

 

I am trying to visually compare headcount one month over another and show how many people have joined, and how many have left.  I could do that with a normal waterfall if it was one dimensional.  However, I want to be able to visualise different groups of 'Types'.  To do that in a waterfall style requires me to calculate how many people were in there in Jan, and then in Feb.  Again...that is no problem using CountRows.  However, I haven't worked out how to write another measure which acts on each row of data.  Hence my use of Calculated Column which as you say is bogus.

 

What would the syntax of a measure be that replicated the logic of my effort, but did so in a measure?

 

Gerald

Ok, I finally got what you are trying to do. But. Will your data only contain data for january or february? Because hard coding this works in a simple data set like this, but what happens when you have 2 years worth of data? How should it be displayed?

That is the point...I don't want to hard code it.  I have hard coded it to start with simply to show what I want to display, but my ideal solution is to use Measures so that the visualization is dynamic.  I included some simple pictures in the OP of what I want it to look like...do they display for you?

 

Being able to compare 2 months would be a start...the approach I was trying to pursue using Measures and a calculated column could be scaled Jan, Feb, Mar etc and then use a SWITCH statement...not very elegant I know but workable.  But that is moot given the constraints of Calculated columns. 

 

Obviously a fully scalable, elegant solution would be ideal but I will take what I can get for the moment.

 

Is there some Measure command that allows me to say something like:

 

Measure=IF(Month = "JanJoin" and Type = "x" then [Jan], else if Month = "JanLeave" and Type = "x" then [Feb], else if....   etc etc

or

Measure= SWITCH(TRUE(), Month="JanJoin" && Type = "x",[Jan],Month = "JanLeave" && Type = "x",[Feb],

 

one problem I can see is that using the conditional test "Month =" is looking up a 'naked' column.

 

 

do you need have the employees as legend?

No Sturla...not necessarily.  However I would want to be able to use Type as a legend. 

 

Thanks for the time you are taking on this...much appreciated

 

Gerald

So, here is a draft: pbix

 

I have added data for march as well. In power query a new table is generated, so that the values that goes on the x-axis is dynamically handled.

 

And the measure is dynamic as well. The DAX of the measure might look a bit scary, but it is not very complex DAX. 

Waterfall - Stacked Bar.PNG

new version: pbix 

 

This is as close as I can get, had to make use of a dummy Type, x, in order to get new and lost up on the Y-axis.

 

Cheers,
Sturla

Anonymous
Not applicable

Sturla, Thanks for putting in so much effort. My hope was that when filtered on a type, the 'invisible' value would re-calculate so that the Joiner/Leaver bar would start from a different place. So by selecting Permanent, the New would show as raising the total from 2 to 3 and not the original 3 to 4. Will understand if you feel you have spent enough time on this already!! Gerald

good point that the chart should work when filtering for type. But, to do so I would need to add yet another stand-alone table, with even more code, and I am not sure it would even work. What you can do instead, is to have three versions of your table. 1 with both types, as you have now, and 2 tables containing only Permanent and Temp, respectively. Duplicate the measure in each table, and create 3 identical charts. Then instead of a slicer, create buttons and bookmarks to switch between them.

Sturla,

 

Thank you for your outstanding effort on this - way beyond the call of duty.  It will take me a little while to work through your solution and see what I can learn and I will let you know where I get.

 

Thanks once again!

 

Gerald

Sturla,

 

Many thanks.  Could I just clarify, though that we are on the same page.

 

One of the major issues I am trying to deal with is to make the chart look like a waterfall chart, to show changes one month to the next.

 

So...if the first month has say, 5 people, and the 2nd month has two people added, then the chart would look as follows:

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.