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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Chirag4370
Helper I
Helper I

Total bar in Hierarchical bar chart

Hello Experts,
I'm stuck on total bars in a hierarchical bar chart. 

Find current & desired output and Data Model from below SnapShots. and used DAX to get Total. 

Thaks in advance.

chart cut.pngData Model.png

Values for "Total" derived by DAX:

 

Val+Total = 
VAR total = CALCULATE(SUM(Data[Val]), ALLSELECTED('Data'))

RETURN
IF(
    SELECTEDVALUE('Date'[DateText]) = "Total" || SELECTEDVALUE(Cat[Cat]) = "Total",
    total,
    SUM(Data[Val])
)

 

 

2 ACCEPTED SOLUTIONS
v-jianpeng-msft
Community Support
Community Support

Hi, @Chirag4370 

Based on your description, I use the following sample data:

vjianpengmsft_0-1710924014115.png

vjianpengmsft_1-1710924027770.png

vjianpengmsft_2-1710924050630.png

I re-edited the relationship between the tables as shown in the image below:

vjianpengmsft_3-1710924108164.png

I use the following DAX expression:

Val+Total =
VAR _data =
    SELECTEDVALUE ( 'Date'[DateText] )
VAR _currentcat =
    MAX ( Data[Cat] )
VAR _total =
    CALCULATE (
        SUM ( Data[Val] ),
        FILTER ( ALLSELECTED ( 'Data' ), 'Data'[Cat] = _currentcat )
    )
RETURN
    IF (
        MAX ( 'Date'[DateText] ) = "Total",
        _total,
        CALCULATE ( SUM ( Data[Val] ), 'Data'[DateText] = _data )
    )

Here are the results:

vjianpengmsft_4-1710924239116.png

I've provided the PBIX that I used this time and it would be great if it would help you.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

HI @Chirag4370 ,

 

Using  the model you shared you can do the following measure:

Val+Total = 
VAR total = 
  
       CALCULATE(SUM(Data[Val]), ALL(Data))

VAR total_ = 
IF(
    ISFILTERED(Cat[Cat]),
    CALCULATE(SUM(Data[Val]), ALLSELECTED('Date')),
    CALCULATE(SUM(Data[Val]), ALLSELECTED('Cat'))
)

RETURN
SWITCH(TRUE(),
    SELECTEDVALUE('Date'[DateText]) = "Total" && SELECTEDVALUE(Cat[Cat]) = "Total",
    total,
    SELECTEDVALUE('Date'[DateText]) = "Total" || SELECTEDVALUE(Cat[Cat]) = "Total",total_,
    SUM(Data[Val])
)

MFelix_0-1711555887284.png

 

MFelix_1-1711555894530.png

File attach.


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
Chirag4370
Helper I
Helper I

Hello, @v-jianpeng-msft 

Thank You for you guidence.

Actualy I'm looking for GrandTotal also, as I given snapshot tagged with desired output.

is it possible? 

HI @Chirag4370 ,

 

Using  the model you shared you can do the following measure:

Val+Total = 
VAR total = 
  
       CALCULATE(SUM(Data[Val]), ALL(Data))

VAR total_ = 
IF(
    ISFILTERED(Cat[Cat]),
    CALCULATE(SUM(Data[Val]), ALLSELECTED('Date')),
    CALCULATE(SUM(Data[Val]), ALLSELECTED('Cat'))
)

RETURN
SWITCH(TRUE(),
    SELECTEDVALUE('Date'[DateText]) = "Total" && SELECTEDVALUE(Cat[Cat]) = "Total",
    total,
    SELECTEDVALUE('Date'[DateText]) = "Total" || SELECTEDVALUE(Cat[Cat]) = "Total",total_,
    SUM(Data[Val])
)

MFelix_0-1711555887284.png

 

MFelix_1-1711555894530.png

File attach.


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



Hello, @MFelix 
Your solution is just amazing. Thank You so much. Truly You are Super User.

v-jianpeng-msft
Community Support
Community Support

Hi, @Chirag4370 

Based on your description, I use the following sample data:

vjianpengmsft_0-1710924014115.png

vjianpengmsft_1-1710924027770.png

vjianpengmsft_2-1710924050630.png

I re-edited the relationship between the tables as shown in the image below:

vjianpengmsft_3-1710924108164.png

I use the following DAX expression:

Val+Total =
VAR _data =
    SELECTEDVALUE ( 'Date'[DateText] )
VAR _currentcat =
    MAX ( Data[Cat] )
VAR _total =
    CALCULATE (
        SUM ( Data[Val] ),
        FILTER ( ALLSELECTED ( 'Data' ), 'Data'[Cat] = _currentcat )
    )
RETURN
    IF (
        MAX ( 'Date'[DateText] ) = "Total",
        _total,
        CALCULATE ( SUM ( Data[Val] ), 'Data'[DateText] = _data )
    )

Here are the results:

vjianpengmsft_4-1710924239116.png

I've provided the PBIX that I used this time and it would be great if it would help you.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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