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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ashwani_gupta
Frequent Visitor

Adding calculated Total Line to Chart

Hi All,

 

I have a Column Graph for which I want to add a Total Line. I have following 3 tables.

 

Table 1: Asset

Fields: Asset ID, Location City

 

Table 2: Users

Fields: User ID, Location City

 

Table 3: Region

Fields: Location City, Region.

 

Here, Regions are like Asia, Europe, North America, South America etc. Multiple Location City could be under one region for ex: under Asia, it could be Tokyo, Manila, Delhi etc.

 

I am trying to portray difference between No. of Assets and No. of Users in a Region and multiple by a Potential Cost of an asset for ex: 50 USD.

 

So, if Asia Region has 150 Asset and 100 Users then Additonal Cost for Asia will be 150-100 = 50 mutiplied by 50 USD = 2500 USD.

 

But if a region has less no. of Assets than users, Additional cost be zero. i.e. if Europe has 200 Assets and 225 Users then Additional Cost will be zero.

 

I have created a Measure in Table 1 'Asset' like:

AdditionalCost = if(
        COUNTROWS('Asset')-COUNTROWS('Users')>0,
        ((COUNTROWS('Asset')-COUNTROWS('Users'))*50),
        ((COUNTROWS('Asset')-COUNTROWS('Users'))*0)
    )

 

 With this Measure, I have created a column Chart with X-Axis as 'Region' from Table 3 and Y-Axis is Measure "Additional Cost" from Table 1. Table 1 'Asset' and Table 2 'Users' are connected to Table 3 'Regions' via field Location City. 

 

I want to add one more line in my Column Chart as "Total Addition Cost" which will be sum of all Additional Cost for Regions whereever No. of Assets is mroe than No. of Users i.e. Positive Additional Cost.

 

How can I do this? Please guide me.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @ashwani_gupta 
Please refer to the attached sample file for more details

1.png2.png3.png

AdditionalCost = 
VAR CurrentRegion = SELECTEDVALUE ( Locations[Region] )
VAR Count1 = COUNTROWS ( Assets ) - COUNTROWS ( Users )
VAR Count2 = IF ( Count1 > 0, Count1, 0.00001 )
VAR Count3 = 
    SUMX ( 
        ALLSELECTED ( Locations[Region] ),
        VAR Count4 = CALCULATE ( COUNTROWS ( Assets ) - COUNTROWS ( Users ) )
        RETURN
            IF ( Count4 > 0, Count4, 0 )
    )
VAR AdditionalCount = IF ( CurrentRegion = "Total", Count3, Count2 )
VAR AdditionalCost = AdditionalCount * 50
RETURN
    AdditionalCost
SortingMeasure = 
IF ( 
    SELECTEDVALUE ( Locations[Region] ) = "Total", 
    - 0.00001,
    [AdditionalCost] / 10000000000
)

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @ashwani_gupta 
Please refer to the attached sample file for more details

1.png2.png3.png

AdditionalCost = 
VAR CurrentRegion = SELECTEDVALUE ( Locations[Region] )
VAR Count1 = COUNTROWS ( Assets ) - COUNTROWS ( Users )
VAR Count2 = IF ( Count1 > 0, Count1, 0.00001 )
VAR Count3 = 
    SUMX ( 
        ALLSELECTED ( Locations[Region] ),
        VAR Count4 = CALCULATE ( COUNTROWS ( Assets ) - COUNTROWS ( Users ) )
        RETURN
            IF ( Count4 > 0, Count4, 0 )
    )
VAR AdditionalCount = IF ( CurrentRegion = "Total", Count3, Count2 )
VAR AdditionalCost = AdditionalCount * 50
RETURN
    AdditionalCost
SortingMeasure = 
IF ( 
    SELECTEDVALUE ( Locations[Region] ) = "Total", 
    - 0.00001,
    [AdditionalCost] / 10000000000
)

Worked Perfectly

 

Thanks @tamerj1 

tamerj1
Super User
Super User

Hi @ashwani_gupta 
Do you mean you want to add a total column (bar) in the chart? Can you provide a small sample of data?

@tamerj1 

 

Table 1: Asset

ashwani_gupta_0-1704270365884.png

 

Table 2: Users

ashwani_gupta_1-1704270421921.png

 

Table 3: Region

ashwani_gupta_2-1704270449489.png

 

Measure added in Table 1: Asset

ashwani_gupta_3-1704270505453.png

 

Graph Preapred:

ashwani_gupta_4-1704270540602.png

 

Query: How to add an additional Bar "Total Additional Cost" in exisitng Graph. The "Total Additional cost" here will be USD 200. (Europe 150 + Asia 50 + Americas 0). Please note that for Region Americas - calculation of Additional Cost is ZERO as Americas has More Users than Assets (Asset Count is 5. User Count is 7).

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.