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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
ipmh97
New Member

Adding Grand total to column chart calculating distinct count

Hi,

 

I am ttrying to do up a bar chart for countries across years with the distinct count of IDs as the value. I am also trying to add a grand total column at the side of each chart, looking something like this:

Screenshot 2023-09-19 at 5.51.04 PM.png

How do i go about doing this?

I have attached a very simplified version fo my data, bearing in mind the total should work and be accurate when factoring in slicers and filters.

https://drive.google.com/file/d/1OXN8FfogWTv88xxNeWauqvHcoOShXZOb/view?usp=share_link

 

Thank you for the help!

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

Hi @ipmh97 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table and measures. 

Table 2 = var a=SUMMARIZE(Sheet1,[Year])
var b={"Total"}
var c=SUMMARIZE(Sheet1,[Country])
return GENERATEALL(UNION(a,b),c)
Measure 4 = var a=SUMMARIZE(FILTER('Table 2',[Year]<>"Total"),'Table 2'[Year])
return IF(SELECTEDVALUE('Table 2'[Year])<>"Total",CALCULATE(DISTINCTCOUNT(Sheet1[ID]),FILTER('Sheet1',[Year] in a&&[Country] in VALUES('Table 2'[Country]))),0)
Measure 5 = var a=SUMMARIZE(FILTER(ALLSELECTED('Table 2'),[Year]<>"Total"),[Year],[Country],"Sum",[Measure 4])
return IF(SELECTEDVALUE('Table 2'[Year])="Total",SUMX(FILTER(a,[Country] in VALUES('Table 2'[Country])),[Sum]),SUMX(FILTER(a,[Year] in VALUES('Table 2'[Year])&&[Country] in VALUES('Table 2'[Country])),[Sum]))

(3) Then the result is as follows.

vtangjiemsft_0-1695288792536.png

Best Regards,

Neeko Tang

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

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @ipmh97 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table and measures. 

Table 2 = var a=SUMMARIZE(Sheet1,[Year])
var b={"Total"}
var c=SUMMARIZE(Sheet1,[Country])
return GENERATEALL(UNION(a,b),c)
Measure 4 = var a=SUMMARIZE(FILTER('Table 2',[Year]<>"Total"),'Table 2'[Year])
return IF(SELECTEDVALUE('Table 2'[Year])<>"Total",CALCULATE(DISTINCTCOUNT(Sheet1[ID]),FILTER('Sheet1',[Year] in a&&[Country] in VALUES('Table 2'[Country]))),0)
Measure 5 = var a=SUMMARIZE(FILTER(ALLSELECTED('Table 2'),[Year]<>"Total"),[Year],[Country],"Sum",[Measure 4])
return IF(SELECTEDVALUE('Table 2'[Year])="Total",SUMX(FILTER(a,[Country] in VALUES('Table 2'[Country])),[Sum]),SUMX(FILTER(a,[Year] in VALUES('Table 2'[Year])&&[Country] in VALUES('Table 2'[Country])),[Sum]))

(3) Then the result is as follows.

vtangjiemsft_0-1695288792536.png

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors