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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hideakisuzuki01
Helper II
Helper II

Totals not showing for measures

Hi, 

I have the below data, 

hideakisuzuki01_0-1735187770288.png

And I need to compare different versions of budget (there are only two in the screenshot but there are more in real data).

There are two Slicers and users choose "Budget1" and "Budget2" in each Slicer for this example.


What I need is the below.

hideakisuzuki01_1-1735188097146.png

 

I wrote the below DAX 

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

M_Negative3 =
var SelectedProduct = SELECTEDVALUE('Fact'[Product])
var SelectedRegion = SELECTEDVALUE('Fact'[Region])
var SelectedVersion1 = SELECTEDVALUE('BudgetVersion1'[BugetVersion])
var SelectedVersion2 = SELECTEDVALUE('BudgetVersion2'[BugetVersion])

var value1 =
CALCULATE(
    SUM('Fact'[Cost]),
     'Fact'[Product] = SelectedProduct,
     'Fact'[Region] = SelectedRegion,
     'Fact'[BugetVersion] = SelectedVersion1)

var value2 =
CALCULATE(
    SUM('Fact'[Cost]),
     'Fact'[Product] = SelectedProduct,
     'Fact'[Region] = SelectedRegion,
     'Fact'[BugetVersion] = SelectedVersion2)

var value3 = value1 - value2
var value4 = IF(value3 < 0, value3, 0)
return value4

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

 

I see correct numbers for each row but there is no total as below. I know the Totals are not working because SELECTEDVALUE functinos return blank for the Totals, but I cannot think of any way of geting this to work any other way.

hideakisuzuki01_2-1735188288604.png

 

What can I do to display totals here ?

 

Regards

 

 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1735189890826.png

 

 

Jihwan_Kim_0-1735189839449.png

 

Cost budget version 1: = 
CALCULATE ( SUM ( cost[cost] ), budget_version[budget_version] = "b01" )

 

Cost budget version 2: = 
CALCULATE ( SUM ( cost[cost] ), budget_version[budget_version] = "b02" )

 

Positive: = 
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( cost, 'product'[product], region[region] ),
            "@result", [Cost budget version 1:] - cost[Cost budget version 2:]
        ),
        [@result] > 0
    )
RETURN
    SUMX ( _t, [@result] )

 

 

Negative: = 
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( cost, 'product'[product], region[region] ),
            "@result", [Cost budget version 1:] - cost[Cost budget version 2:]
        ),
        [@result] < 0
    )
RETURN
    SUMX ( _t, [@result] )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
hideakisuzuki01
Helper II
Helper II

It worked just as I expected, thanks !

And you did it so quickly too, I am amazed at your solution in such a short amount of time.

I can't thank you enough, 

Btw, do  you provide a consulting service? if you do, I am willing to pay for it when I need help in the future.

danextian
Super User
Super User

Hi @hideakisuzuki01 

 

There is no total because you used SELECTEDVALUE which if there are more than one distinct values will return blank and  this is very likely at the total level be in columns or rows. Also, there is no need to use SELECTEDVALUE in the context of your measure if the filter is coming from the fact or a related dimensions table.

 

The measure below a ssumes that BudgetVersion doesnt have a relationship to your fact table.

M_Negative3 =
VAR SelectedVersion1 =
    SELECTEDVALUE ( 'BudgetVersion1'[BugetVersion] )
VAR SelectedVersion2 =
    SELECTEDVALUE ( 'BudgetVersion2'[BugetVersion] )
VAR value1 =
    CALCULATE ( SUM ( 'Fact'[Cost] ), 'Fact'[BugetVersion] = SelectedVersion1 )
VAR value2 =
    CALCULATE ( SUM ( 'Fact'[Cost] ), 'Fact'[BugetVersion] = SelectedVersion2 )
VAR value3 = value1 - value2
VAR value4 =
    IF ( value3 < 0, value3, 0 )
RETURN
    value4

 

To  get the t otal sum:

SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Fact', 'Fact'[Product], 'Fact'[Region] ),
        "@M", [M_Negative3]
    ),
    [@M]
)

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1735189890826.png

 

 

Jihwan_Kim_0-1735189839449.png

 

Cost budget version 1: = 
CALCULATE ( SUM ( cost[cost] ), budget_version[budget_version] = "b01" )

 

Cost budget version 2: = 
CALCULATE ( SUM ( cost[cost] ), budget_version[budget_version] = "b02" )

 

Positive: = 
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( cost, 'product'[product], region[region] ),
            "@result", [Cost budget version 1:] - cost[Cost budget version 2:]
        ),
        [@result] > 0
    )
RETURN
    SUMX ( _t, [@result] )

 

 

Negative: = 
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( cost, 'product'[product], region[region] ),
            "@result", [Cost budget version 1:] - cost[Cost budget version 2:]
        ),
        [@result] < 0
    )
RETURN
    SUMX ( _t, [@result] )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.