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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ashwani_gupta
Frequent Visitor

Enter Total BAR in Bar Chart

Hello All,

 

I am facing problems in getting Total as one of the Bar in Bar Chart. My current Graph looks like this:

 

ashwani_gupta_1-1707208006363.png   

ashwani_gupta_2-1707208034749.png

I want Total (i.e. 13970) also to come as a BAR in above BAR Chart.

 

My Tables structure is like this

Table 1: Computers (List of Computers and its Principal User (below is only Sample Data))

 

IDShared DevicePrincipal UserPrinciple StateLocation
C10A1ActiveStuttgart
C20A1ActiveStuttgart
C30A1ActiveStuttgart
C40A2ActiveStuttgart
C50A1ActiveStuttgart
C60A3ActiveStuttgart
C70A1ActiveStuttgart
C80A1ActiveStuttgart
C90A1ActiveStuttgart
C100A1ActiveStuttgart
C110A1ActiveStuttgart
C120A1ActiveStuttgart
C130A1ActiveStuttgart
C140A1ActiveStuttgart
C150A1ActiveStuttgart
C160A1ActiveStuttgart
C170A4ActiveStuttgart
C180A5ActiveStuttgart

 

In table 1, I have created an additional column as 

IndexCreated = 1

 

Table 2: Country (Mapping of Location and Country)

                  

Location

 

Country

 

ItupevaBrazil
ChangchunChina
ChangshaChina
ChangzhouChina
DrancyPortugal
StuttgartGermany
Stuttgart 2Germany
HildesheimGermany
GlobalGermany
IngolstadtGermany
MuenchenGermany
SchwieberdingenGermany
MiskolcHungary
BengaluruIndia
TorinoPortugal
LermaMexico
Vila do CondePortugal
TretoSpain
YokohamaPortugal
NoviMexico
Yongin-SiPortugal
GermanyGermany
PortugalPortugal
TotalTotal

  

What is my output graph: In my graph, I want to highlight whoever User is using more than 1 computer is basically having Saving Potential if we take additional computers back from these users. So, I am trying to count all users having more than 1 computers assigned to them. Sum all these additional computers in that country and subratct total number such "Users with multiple computers" in that country. The subtraction is to be performed to count only additional computers. For ex: if in a country there are 3 users with User1 having Comp1, Comp2, Comp3. User 2 having Comp4, Comp5 and User 3 having Comp6 assigned to them.

 

Additonal Comp with User1: Comp2 and Comp3

Addditional Comp with User2: Comp5

Additional Comp with User3: NA

 

Total Additional Asset in that country: 3 (Comp2, Comp3 and Comp5)

 

I have tried to create Measure like this in Table 2:  Country (But it didn't work)

 

 

MPCS = 
VAR CurrentCountry = SELECTEDVALUE ( 'Country'[Country] )

var tab1= FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1)
var TAD = CALCULATE(SUM(computers[IndexCreated]),tab1)

var AD= TAD - COUNTROWS(FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1))

VAR CountTotal = 
    SUMX ( 
        ALLSELECTED ( 'Country'[Country] ),

              
        var tab2= FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1)
        var TAD2 = CALCULATE(SUM(computers[IndexCreated]),tab2)

        var AD2= TAD2 - COUNTROWS(FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1))


        RETURN
            IF(AD2>0,AD2,0)
    )

VAR AdditionalCount = IF ( CurrentCountry = "Total", CountTotal, AD )
VAR AdditionalCost = AdditionalCount * 20
RETURN
    AdditionalCost

 

 

My understaning here is this part: 

var tab2= FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1)
var TAD2 = CALCULATE(SUM(computers[IndexCreated]),tab2)

 

is working correctly outside sumx, but inside sumx is not working. How can I make it work? Or any other alternate approach?

 

1 ACCEPTED SOLUTION
talespin
Solution Sage
Solution Sage

hi @ashwani_gupta 

 

Is this what you wanted?

 

Logic :

Count distinct users per location, country and subtract from count of computers per location, country.

Create a summarized table with all the countries and then calculate above information, then aggregate at desired level.

DimCountry includes a row for Total.

 

Measure

-------------------

Spare Computers =
VAR _SelCountry = SELECTEDVALUE(DimCountry[Country])
VAR _SummTbl =
ADDCOLUMNS(
            SUMMARIZE(ALL(DimCountry[Country], DimCountry[Location]), DimCountry[Country], DimCountry[Location]),
            "@UserCount",
            VAR _Country = [Country]
            VAR _Location = [Location]
            RETURN CALCULATE(DISTINCTCOUNT(FactComputer[Principal User]), NOT(ISBLANK(FactComputer[Principal User])), DimCountry[Country] = _Country, DimCountry[Location] = _Location) ,
            "@ComputerCount",
            VAR _Country = [Country]
            VAR _Location = [Location]
            RETURN CALCULATE( COUNT(FactComputer[ID]), NOT(ISBLANK(FactComputer[Principal User])), DimCountry[Country] = _Country, DimCountry[Location] = _Location)
)

VAR _TotalCount =
SUMX(
    _SummTbl,
    [@ComputerCount] - [@UserCount]
)


RETURN SUMX( FILTER(_SummTbl, [Country] = _SelCountry),
             IF([Country] = "Total", _TotalCount, [@ComputerCount] - [@UserCount])
)
 
 

 

talespin_2-1707715405991.png

talespin_3-1707715416924.png

 

This is the Data I used

IDShared DevicePrincipal UserPrinciple StateLocation

C10A1ActiveHildesheim
C10A1ActiveMuenchen
C10A1ActiveMiskolc
C10A1ActiveStuttgart
C10A1ActiveLerma
C10A1ActiveNovi
C10A1ActiveDrancy
C100A1ActiveStuttgart
C100A1ActiveHildesheim
C100A1ActiveMuenchen
C100A1ActiveMiskolc
C100A1ActiveLerma
C100A1ActiveNovi
C100A1ActiveDrancy
C110A1ActiveStuttgart
C110A1ActiveHildesheim
C110A1ActiveMuenchen
C110A1ActiveMiskolc
C110A1ActiveLerma
C110A1ActiveNovi
C110A1ActiveDrancy
C120A1ActiveStuttgart
C120A1ActiveHildesheim
C120A1ActiveMuenchen
C120A1ActiveMiskolc
C120A1ActiveLerma
C120A1ActiveNovi
C120A1ActiveDrancy
C130A1ActiveMiskolc
C130A1ActiveStuttgart
C130A1ActiveHildesheim
C130A1ActiveMuenchen
C130A1ActiveLerma
C130A1ActiveNovi
C130A1ActiveDrancy
C140A1ActiveStuttgart
C140A1ActiveHildesheim
C140A1ActiveMuenchen
C140A1ActiveMiskolc
C140A1ActiveLerma
C140A1ActiveNovi
C140A1ActiveDrancy
C150A1ActiveStuttgart
C150A1ActiveHildesheim
C150A1ActiveMuenchen
C150A1ActiveMiskolc
C150A1ActiveLerma
C150A1ActiveNovi
C150A1ActiveDrancy
C160A1ActiveStuttgart
C160A1ActiveHildesheim
C160A1ActiveMuenchen
C160A1ActiveMiskolc
C160A1ActiveLerma
C160A1ActiveNovi
C160A1ActiveDrancy
C170A4ActiveStuttgart
C170A4ActiveHildesheim
C170A4ActiveMuenchen
C170A4ActiveMiskolc
C170A4ActiveLerma
C170A4ActiveNovi
C170A4ActiveDrancy
C180A5ActiveStuttgart
C180A5ActiveHildesheim
C180A5ActiveMuenchen
C180A5ActiveMiskolc
C180A5ActiveLerma
C180A5ActiveNovi
C180A5ActiveDrancy
C20A1ActiveStuttgart
C20A1ActiveHildesheim
C20A1ActiveMuenchen
C20A1ActiveMiskolc
C20A1ActiveLerma
C20A1ActiveNovi
C20A1ActiveDrancy
C30A1ActiveStuttgart
C30A1ActiveHildesheim
C30A1ActiveMuenchen
C30A1ActiveMiskolc
C30A1ActiveLerma
C30A1ActiveNovi
C30A1ActiveDrancy
C40A2ActiveStuttgart
C40A2ActiveHildesheim
C40A2ActiveMuenchen
C40A2ActiveMiskolc
C40A2ActiveLerma
C40A2ActiveNovi
C40A2ActiveDrancy
C50A1ActiveStuttgart
C50A1ActiveHildesheim
C50A1ActiveMuenchen
C50A1ActiveMiskolc
C50A1ActiveLerma
C50A1ActiveNovi
C50A1ActiveDrancy
C60A3ActiveStuttgart
C60A3ActiveHildesheim
C60A3ActiveMuenchen
C60A3ActiveMiskolc
C60A3ActiveLerma
C60A3ActiveNovi
C60A3ActiveDrancy
C70A1ActiveHildesheim
C70A1ActiveMuenchen
C70A1ActiveMiskolc
C70A1ActiveStuttgart
C70A1ActiveLerma
C70A1ActiveNovi
C70A1ActiveDrancy
C80A1ActiveMiskolc
C80A1ActiveStuttgart
C80A1ActiveHildesheim
C80A1ActiveMuenchen
C80A1ActiveLerma
C80A1ActiveNovi
C80A1ActiveDrancy
C90A1ActiveStuttgart
C90A1ActiveHildesheim
C90A1ActiveMuenchen
C90A1ActiveMiskolc
C90A1ActiveLerma
C90A1ActiveNovi
C90A1ActiveDrancy

 

I hope people don't come after you for taking their spare computers away 😄

View solution in original post

9 REPLIES 9
talespin
Solution Sage
Solution Sage

hi @ashwani_gupta 

 

Is this what you wanted?

 

Logic :

Count distinct users per location, country and subtract from count of computers per location, country.

Create a summarized table with all the countries and then calculate above information, then aggregate at desired level.

DimCountry includes a row for Total.

 

Measure

-------------------

Spare Computers =
VAR _SelCountry = SELECTEDVALUE(DimCountry[Country])
VAR _SummTbl =
ADDCOLUMNS(
            SUMMARIZE(ALL(DimCountry[Country], DimCountry[Location]), DimCountry[Country], DimCountry[Location]),
            "@UserCount",
            VAR _Country = [Country]
            VAR _Location = [Location]
            RETURN CALCULATE(DISTINCTCOUNT(FactComputer[Principal User]), NOT(ISBLANK(FactComputer[Principal User])), DimCountry[Country] = _Country, DimCountry[Location] = _Location) ,
            "@ComputerCount",
            VAR _Country = [Country]
            VAR _Location = [Location]
            RETURN CALCULATE( COUNT(FactComputer[ID]), NOT(ISBLANK(FactComputer[Principal User])), DimCountry[Country] = _Country, DimCountry[Location] = _Location)
)

VAR _TotalCount =
SUMX(
    _SummTbl,
    [@ComputerCount] - [@UserCount]
)


RETURN SUMX( FILTER(_SummTbl, [Country] = _SelCountry),
             IF([Country] = "Total", _TotalCount, [@ComputerCount] - [@UserCount])
)
 
 

 

talespin_2-1707715405991.png

talespin_3-1707715416924.png

 

This is the Data I used

IDShared DevicePrincipal UserPrinciple StateLocation

C10A1ActiveHildesheim
C10A1ActiveMuenchen
C10A1ActiveMiskolc
C10A1ActiveStuttgart
C10A1ActiveLerma
C10A1ActiveNovi
C10A1ActiveDrancy
C100A1ActiveStuttgart
C100A1ActiveHildesheim
C100A1ActiveMuenchen
C100A1ActiveMiskolc
C100A1ActiveLerma
C100A1ActiveNovi
C100A1ActiveDrancy
C110A1ActiveStuttgart
C110A1ActiveHildesheim
C110A1ActiveMuenchen
C110A1ActiveMiskolc
C110A1ActiveLerma
C110A1ActiveNovi
C110A1ActiveDrancy
C120A1ActiveStuttgart
C120A1ActiveHildesheim
C120A1ActiveMuenchen
C120A1ActiveMiskolc
C120A1ActiveLerma
C120A1ActiveNovi
C120A1ActiveDrancy
C130A1ActiveMiskolc
C130A1ActiveStuttgart
C130A1ActiveHildesheim
C130A1ActiveMuenchen
C130A1ActiveLerma
C130A1ActiveNovi
C130A1ActiveDrancy
C140A1ActiveStuttgart
C140A1ActiveHildesheim
C140A1ActiveMuenchen
C140A1ActiveMiskolc
C140A1ActiveLerma
C140A1ActiveNovi
C140A1ActiveDrancy
C150A1ActiveStuttgart
C150A1ActiveHildesheim
C150A1ActiveMuenchen
C150A1ActiveMiskolc
C150A1ActiveLerma
C150A1ActiveNovi
C150A1ActiveDrancy
C160A1ActiveStuttgart
C160A1ActiveHildesheim
C160A1ActiveMuenchen
C160A1ActiveMiskolc
C160A1ActiveLerma
C160A1ActiveNovi
C160A1ActiveDrancy
C170A4ActiveStuttgart
C170A4ActiveHildesheim
C170A4ActiveMuenchen
C170A4ActiveMiskolc
C170A4ActiveLerma
C170A4ActiveNovi
C170A4ActiveDrancy
C180A5ActiveStuttgart
C180A5ActiveHildesheim
C180A5ActiveMuenchen
C180A5ActiveMiskolc
C180A5ActiveLerma
C180A5ActiveNovi
C180A5ActiveDrancy
C20A1ActiveStuttgart
C20A1ActiveHildesheim
C20A1ActiveMuenchen
C20A1ActiveMiskolc
C20A1ActiveLerma
C20A1ActiveNovi
C20A1ActiveDrancy
C30A1ActiveStuttgart
C30A1ActiveHildesheim
C30A1ActiveMuenchen
C30A1ActiveMiskolc
C30A1ActiveLerma
C30A1ActiveNovi
C30A1ActiveDrancy
C40A2ActiveStuttgart
C40A2ActiveHildesheim
C40A2ActiveMuenchen
C40A2ActiveMiskolc
C40A2ActiveLerma
C40A2ActiveNovi
C40A2ActiveDrancy
C50A1ActiveStuttgart
C50A1ActiveHildesheim
C50A1ActiveMuenchen
C50A1ActiveMiskolc
C50A1ActiveLerma
C50A1ActiveNovi
C50A1ActiveDrancy
C60A3ActiveStuttgart
C60A3ActiveHildesheim
C60A3ActiveMuenchen
C60A3ActiveMiskolc
C60A3ActiveLerma
C60A3ActiveNovi
C60A3ActiveDrancy
C70A1ActiveHildesheim
C70A1ActiveMuenchen
C70A1ActiveMiskolc
C70A1ActiveStuttgart
C70A1ActiveLerma
C70A1ActiveNovi
C70A1ActiveDrancy
C80A1ActiveMiskolc
C80A1ActiveStuttgart
C80A1ActiveHildesheim
C80A1ActiveMuenchen
C80A1ActiveLerma
C80A1ActiveNovi
C80A1ActiveDrancy
C90A1ActiveStuttgart
C90A1ActiveHildesheim
C90A1ActiveMuenchen
C90A1ActiveMiskolc
C90A1ActiveLerma
C90A1ActiveNovi
C90A1ActiveDrancy

 

I hope people don't come after you for taking their spare computers away 😄

@talespin Yes, this approach has worked and I am able to get Total Bar in the graph. Many thanks.

hi @ashwani_gupta ,

 

You're welcome.

some_bih
Super User
Super User

Hi @ashwani_gupta if you have Microsoft 365 account you can share link for file





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

Proud to be a Super User!






@some_bih Please access this PBIX file via this link: 

<<Link Removed>> as solution accepted in a later post.

 

some_bih
Super User
Super User

Hi @ashwani_gupta it is not clear to me what "else" you are doing with your chart or what is your final request, like total is not correct or something else, like you want to know why is not/ working  SUMX...





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

Proud to be a Super User!






@some_bih : I want to get a "Total Bar" in this chart:

ashwani_gupta_0-1707280506806.png

The value of "Total Bar" is sum from all the countries. The meausre that I am trying is not working properly. The counties Bar value is coming correct but "Total Bar" is not showing.

 

 

Hi @ashwani_gupta it is not totally possible to spot issue without model.

Still, try to replace 

ALLSELECTED with VALUES

Otherwise share pbi file





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

Proud to be a Super User!






@some_bih : I am pasting here screenshot of my Relationship:

ashwani_gupta_0-1707479463669.png

I tried changing ALLSELECTED with VALUES, but it didn't change anything. My Graph still looking like same:

ashwani_gupta_1-1707479550115.png

Bar with "TOTAL" still not coming.

 

My measure (in the Table: Country) looks like this now:

 

MPCS = 
VAR CurrentCountry = SELECTEDVALUE ( 'Country'[Country] )

var tab1= FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1)
var TAD = CALCULATE(SUM(computers[IndexCreated]),tab1)

var AD= TAD - COUNTROWS(FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1))

VAR CountTotal = 
    SUMX ( 
        VALUES('Country'[Country] ),

              
        var tab2= FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1)
        var TAD2 = CALCULATE(SUM(computers[IndexCreated]),tab2)

        var AD2= TAD2 - COUNTROWS(FILTER(SUMMARIZE(computers,computers[Principal User],"Total Count",SUM(computers[IndexCreated])),[Total Count]>1))

        
        RETURN
            IF(AD2>0,AD2,0)
    )

VAR AdditionalCount = IF ( CurrentCountry = "Total", CountTotal, AD )
VAR AdditionalCost = AdditionalCount * 20
RETURN
    AdditionalCost

How can I share PBIX to you? Due to organization restriction, I can't upload in Onedrive or Google Drive to share with you the PBIX file.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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