Forum Discussion

bedata1's avatar
bedata1
Frequent Visitor
2 years ago
Solved

Total Column in Bar Chart for multiple years

Hi Community, 

 

I created a bar chart with a total column. 

The goal is, to have just one total column that shows the summarization of all selected years. The Selection is a slicer.

 

I have the following DAX formula: 

 

Total_Sales_Chart =
VAR total_ = CALCULATE([Total_Sales], REMOVEFILTERS(Month_Name), REMOVEFILTERS('Date'[Year]))
VAR maxSelectedYear = CALCULATE(MAX('Date'[Year]), ALLSELECTED('Date'[Year]))
RETURN
IF(
    SELECTEDVALUE(Month_Name[Month_Name]) = "Total" && SELECTEDVALUE('Date'[Year]) = maxSelectedYear,
    total_,
    [Total_Sales]
)
 
It looks great and also the summarization is working fine. The only problem left is that it shows the total in every year but I want that the total is shown just at the last selected year:

Do you have any idea how to reach this goal?

 

Thank you

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi bedata1 ,

    You can update the formula of measure [Total_Sales_Chart] as below to get it:

    Total_Sales_Chart =
    VAR _selmonth =
        SELECTEDVALUE ( Month_Name[Month_Name] )
    VAR _selyear =
        SELECTEDVALUE ( 'Date'[Year] )
    VAR total_ =
        CALCULATE (
            [Total_Sales],
            REMOVEFILTERS ( Month_Name ),
            REMOVEFILTERS ( 'Date'[Year] )
        )
    VAR maxSelectedYear =
        CALCULATE ( MAX ( 'Date'[Year] ), ALL ( 'Date' ) )
    RETURN
        IF (
            _selmonth = "Total",
            IF ( _selyear = maxSelectedYear, total_, BLANK () ),
            [Total_Sales]
        )

    If the above ones can't help you figure out, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi bedata1 ,

    You can update the formula of measure [Total_Sales_Chart] as below to get it:

    Total_Sales_Chart =
    VAR _selmonth =
        SELECTEDVALUE ( Month_Name[Month_Name] )
    VAR _selyear =
        SELECTEDVALUE ( 'Date'[Year] )
    VAR total_ =
        CALCULATE (
            [Total_Sales],
            REMOVEFILTERS ( Month_Name ),
            REMOVEFILTERS ( 'Date'[Year] )
        )
    VAR maxSelectedYear =
        CALCULATE ( MAX ( 'Date'[Year] ), ALL ( 'Date' ) )
    RETURN
        IF (
            _selmonth = "Total",
            IF ( _selyear = maxSelectedYear, total_, BLANK () ),
            [Total_Sales]
        )

    If the above ones can't help you figure out, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards