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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
Rai_BI
Helper IV
Helper IV

How to calculate a value depending on the column in the visual

Hi! Please, some one help me to solve this issue. I've been trying for a long time and I'm failing

Download PBIX here

 

I'm using the fields parameter which allows me to add multiple columns from different dimension tables to the visual.

I need to create a DAX measure that calculates the salesperson's target value depending on which 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. 

Take a look

I'm just adding the "Year/"Month" column to the visual. The sum is ok.

Rai_BI_0-1708521000184.png

 

Now I'm adding the "Year/"Month" and "Name Seller1" column to the visual. The sum is not correct, because I only need to see the seller1's goal

Rai_BI_1-1708521235796.png

 

Now I'm adding the "Year/"Month" and "Name Seller2" column to the visual. The sum is not correct, because I only need to see the seller2's goal

Rai_BI_2-1708521922751.png

 

Now I'm adding the "Year/"Month" and "Name Seller 1" and "Name Seller2" column to the visual. The sum is correct but it's because the grand total always returns the sum of the two goals. It doesn't check if it's one of the conditionals of the SWITCH that is active.

Rai_BI_3-1708522099700.png

 

In other words, the DAX measure must check whether only one column or both "Seller Name1" and "Seller Name2" columns are in the visual to calculate the correct value according to the presence of the columns.

 

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


If only the "Name Seller 2" column is applied to the visual, calculate the "Goal Seller 2" measure for each row in the visual and also for the grand total.


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

 

See below the measure I took using the SWITCH function, it checks the three conditionals and correctly calculates the values of each line, but the overall total value is returning an incorrect sum, as it is always returning the sum of the two measurements "Goal Seller 1" and "Goal Seller 2" are independent of which conditional is being satisfied in the SWITCH function.

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])
    ),
    CALCULATE([Goal Seller 1] + [Goal Seller 2])
)

 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

The 'Total' row does not have a Name Seller1 or NameSeller2 context.
You can try the following measure which should give the correct result.

Single Measure v2 = 
var _s1Selected =
CONTAINS(SUMMARIZE(Parameter, Parameter[Parâmetro], Parameter[Parâmetro Campos]), Parameter[Parâmetro], "Name Seller1")
var _s2Selected =
CONTAINS(SUMMARIZE(Parameter, Parameter[Parâmetro], Parameter[Parâmetro Campos]), Parameter[Parâmetro], "Name Seller2")
var _countRows =
ISFILTERED(Parameter)
var _result =
SWITCH(
    TRUE(),
    _s1Selected && NOT(_s2Selected) && _countRows, [Goal Seller 1],
    _s2Selected && NOT(_s1Selected) && _countRows, [Goal Seller 2],
    [Goal Seller 1] + [Goal Seller 2]
)
Return
_result

 

jgeddes_0-1708543847172.pngjgeddes_1-1708543861966.pngjgeddes_2-1708543873919.png

 





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

Proud to be a Super User!





View solution in original post

2 REPLIES 2
jgeddes
Super User
Super User

The 'Total' row does not have a Name Seller1 or NameSeller2 context.
You can try the following measure which should give the correct result.

Single Measure v2 = 
var _s1Selected =
CONTAINS(SUMMARIZE(Parameter, Parameter[Parâmetro], Parameter[Parâmetro Campos]), Parameter[Parâmetro], "Name Seller1")
var _s2Selected =
CONTAINS(SUMMARIZE(Parameter, Parameter[Parâmetro], Parameter[Parâmetro Campos]), Parameter[Parâmetro], "Name Seller2")
var _countRows =
ISFILTERED(Parameter)
var _result =
SWITCH(
    TRUE(),
    _s1Selected && NOT(_s2Selected) && _countRows, [Goal Seller 1],
    _s2Selected && NOT(_s1Selected) && _countRows, [Goal Seller 2],
    [Goal Seller 1] + [Goal Seller 2]
)
Return
_result

 

jgeddes_0-1708543847172.pngjgeddes_1-1708543861966.pngjgeddes_2-1708543873919.png

 





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

Proud to be a Super User!





Thank you very much

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.