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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
harirao
Post Prodigy
Post Prodigy

How to create a new bar in Clustered column chart showing total of three Months

Hello, I have a clustered bar chart, were i have taken Attributes as Months and Values, selected only three months, now i want to add a bra which should be sum of three months values

How can I do this in Power Bi?
Capture1.PNG
I am looking similar solution as created in MS Excel.
Capture2.PNG
Please assist me.

Thank you!

1 ACCEPTED SOLUTION
Arul
Super User
Super User

@harirao ,

try the following steps.

1. Create a calculated table for months and then total to be shown in the visual,

Months = 
UNION(
    VALUES(
        Table[Month Name]),
        ROW("Column1","Total")
)

Arul_0-1680606066566.png

2. Create a incative relationship between newly created table and the existing table with Month name as a common key between the tables,

Arul_1-1680606147591.png

3. Write the below measure,

Sales Total Measure = 
VAR _selected = SELECTEDVALUE(New Table[Month Name])
VAR _result = IF(
    _selected = "Total",CALCULATE(
        SUM(Table[ Sales]),
        ALLSELECTED(New Table[Month Name]),
        USERELATIONSHIP(Table[Month Name],New Table[Month Name])),
    CALCULATE(
        SUM(
            Table[ Sales]),
            Table[Month Name] = _selected)
)
RETURN _result

4. Use the newly created month names and measure in the visual,

Arul_2-1680606440737.png

Thanks,

Arul

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


View solution in original post

7 REPLIES 7
harirao
Post Prodigy
Post Prodigy

@joaoribeiro 

As per the solution mentioned above from @Arul, i have Create a calculated table for months.
so now i am unable to see 'STARTOFMONTH(date)' in Data
Capture4.PNG


Thank you

 

Regards,

@harirao  you can add one more column to your auxiliary table. Please consider the code below, and adjust as needed for your specific case:

Previous Q =
UNION(
DISTINCT(SELECTCOLUMNS(Unpivot_Data, Unpivot_Data[Attribute], Unpivot_Data[StartOfMonth])),
ROW("Column1", "Previous Q", "Column2", 99999)
)
//Column2 as 99999 will set the Previous Q line with a date in the future, so it will be sorted as the last value always



Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️or giving it a kudoe 👍

Thanks!

Best regards,
Joao Ribeiro

Hi @joaoribeiro 
Is there any other solution for Sort Months?
Still not getting correctly result, after doing above mentioned work around.
Capture5.PNG
Data is not visible after adding Column2
Capture6.PNG

Thank you

 

Regards,

Hari

harirao
Post Prodigy
Post Prodigy

@Arul 

By using the above logic i got the solution, now facing the challenge to Sort the Month according to calender like (Feb, Mar, April), which is not working correctly.

Please assist me on this
Capture3.PNG

Thank you

Hi @harirao ,

 

In order to have proper sorting for non numeric values, you can use other column as base. In this case that you are using a month-year column, you can follow the steps below:

  1. Create another column in your Date table for STARTOFMONTH(date)
  2. Select the month-year column  > Sort by Column > Start of Month
  3. After that, the sorting on the visual will follow the same sorting of the date.

You need to create the start of month column, because the "Sort by Column" option will only work if you have unique matches between the two columns, so the "date" column would not work, because there are multiple dates for the same month.

 

joaoribeiro_0-1681292561744.png

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️or giving it a kudoe 👍

Thanks!

Best regards,
Joao Ribeiro

Arul
Super User
Super User

@harirao ,

try the following steps.

1. Create a calculated table for months and then total to be shown in the visual,

Months = 
UNION(
    VALUES(
        Table[Month Name]),
        ROW("Column1","Total")
)

Arul_0-1680606066566.png

2. Create a incative relationship between newly created table and the existing table with Month name as a common key between the tables,

Arul_1-1680606147591.png

3. Write the below measure,

Sales Total Measure = 
VAR _selected = SELECTEDVALUE(New Table[Month Name])
VAR _result = IF(
    _selected = "Total",CALCULATE(
        SUM(Table[ Sales]),
        ALLSELECTED(New Table[Month Name]),
        USERELATIONSHIP(Table[Month Name],New Table[Month Name])),
    CALCULATE(
        SUM(
            Table[ Sales]),
            Table[Month Name] = _selected)
)
RETURN _result

4. Use the newly created month names and measure in the visual,

Arul_2-1680606440737.png

Thanks,

Arul

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


joaoribeiro
Kudo Kingpin
Kudo Kingpin

Hi @harirao, I believe this video can help you achieve your objective - I tested it myself and it worked:

https://www.youtube.com/watch?v=Tbvi7FaybQ8

 

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️or giving it a kudoe 👍

Thanks!

Best regards,
João Ribeiro
Senior BI Consultant

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.