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
jmdatasci
Frequent Visitor

Adding subtotal columns based on a hierarchy Column Chart

Hi there, I have my data set up in a way that I have a time hierarchy - Year>Half>Quarter like this

jmdatasci_0-1701705175911.png

I have the data for each quarter which aggregates up properly etc. 

 

What I would like to do is change my chart from this:

jmdatasci_0-1701704956177.png

to something like this:

jmdatasci_1-1701705001051.png

 

Where the dark blue subtotal/total columns are an aggregate of the lower level data either a sum or average. Is there any way to do this without going too crazy? 

 

Thanks



1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @jmdatasci ,

 

From your description, please try the following steps:

1.Please try code as below to Create a X-axis table.

X-axis = 
var _Year = VALUES('Table'[Year])
var _Qrt =
DATATABLE(
 
    " X axis",STRING,
    "Order",INTEGER,
    {
        {"Q1",1},
        {"Q2",2},
        {"H1",3},
        {"Q3",4},
        {"Q4",5},
        {"H2",6},
        {"FY",7}
    }
)
return
GENERATE (
  _Qrt, _Year
)​

2.Use the following code to create two measures, Value_Measure and Color.

Value_Measure = 
var _QTR = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year]) && 'Table'[Quarter] = MAX('X-axis'[ X axis])))
var _H1 = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year]) && 'Table'[Quarter] IN {"Q1","Q2"}))
var _H2 = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year]) && 'Table'[Quarter] IN {"Q3","Q4"}))
var FY = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year])))
return
IF(_QTR = BLANK(),
    SWITCH(MAX('X-axis'[ X axis]),
           "H1",_H1,
           "H2",_H2,
           "FY",FY
           ),
    _QTR
    )
​
Color = IF(CONTAINSSTRING(MAX('X-axis'[ X axis]),"Q"),"#118DFF","#12239E")​

3.Select your visual object and do the following in the Visualizations pane. vweiyan1msft_0-1701851979776.pngvweiyan1msft_1-1701851987875.png

Result is as below.

vweiyan1msft_2-1701852012195.png

My Sample:

vweiyan1msft_3-1701852028967.png

 

Best Regards,

Yulia Yan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
v-weiyan1-msft
Community Support
Community Support

Hi @jmdatasci ,

 

From your description, please try the following steps:

1.Please try code as below to Create a X-axis table.

X-axis = 
var _Year = VALUES('Table'[Year])
var _Qrt =
DATATABLE(
 
    " X axis",STRING,
    "Order",INTEGER,
    {
        {"Q1",1},
        {"Q2",2},
        {"H1",3},
        {"Q3",4},
        {"Q4",5},
        {"H2",6},
        {"FY",7}
    }
)
return
GENERATE (
  _Qrt, _Year
)​

2.Use the following code to create two measures, Value_Measure and Color.

Value_Measure = 
var _QTR = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year]) && 'Table'[Quarter] = MAX('X-axis'[ X axis])))
var _H1 = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year]) && 'Table'[Quarter] IN {"Q1","Q2"}))
var _H2 = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year]) && 'Table'[Quarter] IN {"Q3","Q4"}))
var FY = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = MAX('X-axis'[Year])))
return
IF(_QTR = BLANK(),
    SWITCH(MAX('X-axis'[ X axis]),
           "H1",_H1,
           "H2",_H2,
           "FY",FY
           ),
    _QTR
    )
​
Color = IF(CONTAINSSTRING(MAX('X-axis'[ X axis]),"Q"),"#118DFF","#12239E")​

3.Select your visual object and do the following in the Visualizations pane. vweiyan1msft_0-1701851979776.pngvweiyan1msft_1-1701851987875.png

Result is as below.

vweiyan1msft_2-1701852012195.png

My Sample:

vweiyan1msft_3-1701852028967.png

 

Best Regards,

Yulia Yan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you so much Yulia! It works, just wanted to add for anyone else looking at this that you can sort the X axis column on the order column like this:
https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column?tabs=powerbi-deskto...

 

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.