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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Rai_BI
Helper IV
Helper IV

Unable to calculate grand total. Is it possible?

Hi all,

Is anyone out there a master of DAX? A Shaolin master of the DAX...

 

I need a DAX measure that calculates the value for each line and for the grand total according to conditionals.

 

If the "Name Seller 1" is in scope then calculate the measure "Goal Seller 1" for each line and for the grand total.

 

If the "Name Seller 2" is in scope then calculate the measure "Goal Seller 2" for each line and for the grand total.

 

If both columns "Name Seller 1" and "Name Seller 2" are in scope then calculate the sum of "Goal Seller 1" and "Goal Seller 2" for each line and for the grand total.

 

I have the following DAX measure which works perfectly for each line, but don´t work for the grand total...

 

Single Measure = 

VAR Seller_1_in_Scope = HASONEFILTER('customer table'[Name Seller1])
VAR Seller_2_in_Scope = HASONEFILTER('customer table'[Name Seller2])

RETURN
SWITCH(
    TRUE(),
        Seller_1_in_Scope && NOT Seller_2_in_Scope, 
        SUMX(
            VALUES('customer table'[Name Seller1]),[Goal Seller 1]),

        Seller_2_in_Scope && NOT Seller_1_in_Scope, 
        SUMX(
            VALUES('customer table'[Name Seller2]),[Goal Seller 2]),

        Seller_1_in_Scope && Seller_2_in_Scope, 
        SUMX(
            SUMMARIZE(
                'customer table',
                'customer table'[Name Seller1],'customer table'[Name Seller2]),
                CALCULATE([Goal Seller 1] + [Goal Seller 2])
        )
)

 

  I´m unable to calculate the grand total for each condition because it is returning blank. Take a look at the print.

Sem título.png

How can i fix it?
Download the PBIX file here

14 REPLIES 14
lbendlin
Super User
Super User

You can use VALUES() against the Field Parameter to figure out if one, the other, or both are selected.

AlexisOlson
Super User
Super User

Do you need all the scope stuff?

 

I'd think you could write the measure much more simply:

 

VAR _Goal1 =
    CALCULATE (
        SUM ( goals[Goal] ),
        USERELATIONSHIP ( 'customer table'[ID Seller1], goals[Seller ID] )
    )
VAR _Goal2 =
    CALCULATE (
        SUM ( goals[Goal] ),
        USERELATIONSHIP ( 'customer table'[ID Seller2], goals[Seller ID] )
    )
RETURN
    _Goal1 + _Goal2

 

No, i need a DAX measure that calculates the value for each line and for the grand total according to conditionals.

If the "Name Seller 1" is in scope then calculate the measure "Goal Seller 1" for each line and for the grand total.

 

If the "Name Seller 2" is in scope then calculate the measure "Goal Seller 2" for each line and for the grand total.

 

If both columns "Name Seller 1" and "Name Seller 2" are in scope then calculate the sum of "Goal Seller 1" and "Goal Seller 2" for each line and for the grand total.

ISINSCOPE is largely meaningless for table visuals. Everything is always in scope.

 

Use Matrix visuals or other visuals that support hierarchies.

@lbendlin I have a field parameter applied to the table with several options to add to the visual such as products, categories, months, dates and also among these options are the columns "Name Seller 1" and "Name Seller 2".

Aha, field parameters! That was unclear to me from your initial explanation. Well, bad news.  The order of selection of field parameter values can not be probed as far as I know.  Happy to be proven wrong.

That's why I'm trying to check if the column is in the visual so I can make the correct calculation.

I already tried that and it didn't work

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

I already provide a PBIX file in my topic here

Am I missing something?

 

lbendlin_0-1708273535783.png

 

It is not right. You are simply adding the two measurements together. First you need to check

 

If the "Name Seller 1" is in scope then calculate the measure "Goal Seller 1" for each line and for the grand total 

 

OR 

 

If the "Name Seller 2" is in scope then calculate the measure "Goal Seller 2" for each line and for the grand total 

 

OR 

 

If both columns "Name Seller 1" and "Name Seller 2" are in scope then calculate the sum of "Goal Seller 1" and "Goal Seller 2" for each line and for the grand total.

 

you can only sum [Goal Seller 1] + [Name Seller 2] If both columns "Name Seller 1" and "Name Seller 2" are in the table visual

We talked about this in the other thread. The concept of scope is not applicable to flat tables. Everything is always in scope.  Maybe you can describe your requirement in different words.

I need to create a DAX measure that calculates the sales value depending on which table column is applied to the table visual. In other words, i need to check whether a specified column is applied to the visual and then calculate the corresponding values.


I have a table that is basically a customer portfolio and this table contains the fields "Customer Name", "Seller Name 1" and "Seller Name 2". Each customer is served by two types of salespeople, salesperson 1 and salesperson 2.

Rai_BI_0-1708347361957.pngRai_BI_1-1708347368916.png

If the "Name Seller 1" column is applied to the visual then calculate the "Goal Seller 1" measure for each row of the visual and also for the grand total.


If the "Name Seller 2" column is applied to the visual then calculate the "Goal Seller 2" measurement for each row of the visual and also for the grand total.


If both columns "Name Seller 1" and "Name Seller 2" are applied to the visual, then calculate the sum of the two measures "Name Seller 1" and "Name Seller 2" for each row and also for the grand total.

See the measurement I took below using the SWITCH function, it checks the three conditionals and correctly calculates the values for each line, but the grand total value is returning empty instead of the total of the condition that is being satisfied

Single Measure = 

VAR Seller_1_in_Scope = HASONEFILTER('customer table'[Name Seller1])
VAR Seller_2_in_Scope = HASONEFILTER('customer table'[Name Seller2])

RETURN
SWITCH(
    TRUE(),
    Seller_1_in_Scope && NOT Seller_2_in_Scope, 
    SUMX(
        VALUES('customer table'[Name Seller1]),[Goal Seller 1]),

    Seller_2_in_Scope && NOT Seller_1_in_Scope, 
    SUMX(
        VALUES('customer table'[Name Seller2]),[Goal Seller 2]),

    Seller_1_in_Scope && Seller_2_in_Scope, 
    SUMX(
        'customer table',
        CALCULATE([Goal Seller 1] + [Goal Seller 2])
)
)

Rai_BI_2-1708347403088.png

I need to ensure that the grand total returns the sum of one of the three conditions.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.