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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Rai_BI
Helper IV
Helper IV

Calculate goals per salesperson using the appropriate relationship.

In Power BI I have a customer table with customer and salesperson data. Each Seller is responsible for their respective customers, that is, each seller is responsible for a group of customers or a portfolio of customers. In this customer table there are the following fields: customer code, customer name, Seller1 code, Seller1 name, Seller2 code, Seller2 name, Seller3 code, Seller3 name. Note that for each customer there are 3 Salespeople responsible for the customer.

I have another table with the goals of each seller and this table contains the fields Month, Seller code, Seller Name

The customer table is related to the target table through the fields codeVendedor1, code Vendedor2 and code Vendedor3.

As you know, only one relationship can remain active, which in this case is the Seller2 code field. The other relationships are inactive and to use them it is necessary to use a relationship function such as the USERELATIONSHIP function.

I need a DAX measure that calculates the goal of each Seller so that, if the name Seller1 is in scope, then it calculates Seller1's goals using the appropriate relationship.

If the name Seller2 is in scope, then calculate Seller2's goals using the appropriate relationship.

I made the following DAX measurement below, but it is working in parts, as the totalizer is returned empty or BLANK, I need the totalizer to respect the sum of the goals of EACH seller.

DAX MEASUREMENT...

SWITCH (
TRUE(),
HASONEVALUE('Customers'[Seller code1]),
CALCULATE(
COALESCE(
SUM('Goals'[GoalsValue]),
0
),
USERELATIONSHIP('Customers'[seller code1], 'Goals'[seller code])
),
HASONEVALUE('Customers'[Seller code2]),
CALCULATE(
COALESCE(
SUM('Goals'[GoalsValue]),
0
),
USERELATIONSHIP('Customers'[Seller code2], 'Goals'[Seller code])
),
HASONEVALUE('Customers'[Seller code3]),
CALCULATE(
COALESCE(
SUM('Goals'[GoalsValue]),
0
),
USERELATIONSHIP('Customers'[Seller code3], 'Goals'[Seller code])
),
0
)

1 ACCEPTED SOLUTION

Hi @Rai_BI ,

 

We can create a field parameter.

vtangjiemsft_0-1705991708307.png

Then we can create a measure.

Measure = 
SWITCH (
    TRUE (),
    SELECTEDVALUE ( Parameter[Parameter Order] ) = 0, SUMX ( VALUES ( 'customer table'[Name Seller1] ), [Goals] ),
    SELECTEDVALUE ( Parameter[Parameter Order] ) = 1, SUMX ( VALUES ( 'customer table'[Name Seller2] ), [Goals] ),
    SUMX ( VALUES ( 'customer table'[Name Seller3] ), [Goals] )
)

vtangjiemsft_1-1705991889934.png

If you do not want to display field parameter slicers, you can create a slicer table and a measure.

Slicer = DATATABLE ( 
    "Seller", STRING, 
    {
        { "Name Seller1" },
        { "Name Seller2" },
        { "Name Seller3" }
    }
) 
Measure 4 = 
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'Slicer'[Seller]) = "Name Seller1", SUMX ( VALUES ( 'customer table'[Name Seller1] ), [Goals] ),
    SELECTEDVALUE ( 'Slicer'[Seller]) = "Name Seller2",SUMX ( VALUES ( 'customer table'[Name Seller2] ), [Goals] ),
    SUMX ( VALUES ( 'customer table'[Name Seller3] ), [Goals] )
)

Edit interactions for each slicer in the format pane and hide the slicers.

vtangjiemsft_2-1705993424829.pngvtangjiemsft_3-1705993442883.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

6 REPLIES 6
v-tangjie-msft
Community Support
Community Support

Hi @Rai_BI ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create measures.

Measure 1 = SUMX(VALUES('customer table'[Name Seller1]),[Goals])
Measure 2 = SUMX(VALUES('customer table'[Name Seller2]),[Goals])
Measure 3 = SUMX(VALUES('customer table'[Name Seller3]),[Goals])

(3) Then the result is as follows.

vtangjiemsft_0-1705910175582.pngvtangjiemsft_1-1705910189043.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Thank you very much, I think we are almost there. However, you created three measurements, I need to use these three measurements in just one.
Because I developed a single report for all sellers, if I use three different measures I will have to make three different reports.

Hi @Rai_BI ,

 

We can create a field parameter.

vtangjiemsft_0-1705991708307.png

Then we can create a measure.

Measure = 
SWITCH (
    TRUE (),
    SELECTEDVALUE ( Parameter[Parameter Order] ) = 0, SUMX ( VALUES ( 'customer table'[Name Seller1] ), [Goals] ),
    SELECTEDVALUE ( Parameter[Parameter Order] ) = 1, SUMX ( VALUES ( 'customer table'[Name Seller2] ), [Goals] ),
    SUMX ( VALUES ( 'customer table'[Name Seller3] ), [Goals] )
)

vtangjiemsft_1-1705991889934.png

If you do not want to display field parameter slicers, you can create a slicer table and a measure.

Slicer = DATATABLE ( 
    "Seller", STRING, 
    {
        { "Name Seller1" },
        { "Name Seller2" },
        { "Name Seller3" }
    }
) 
Measure 4 = 
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'Slicer'[Seller]) = "Name Seller1", SUMX ( VALUES ( 'customer table'[Name Seller1] ), [Goals] ),
    SELECTEDVALUE ( 'Slicer'[Seller]) = "Name Seller2",SUMX ( VALUES ( 'customer table'[Name Seller2] ), [Goals] ),
    SUMX ( VALUES ( 'customer table'[Name Seller3] ), [Goals] )
)

Edit interactions for each slicer in the format pane and hide the slicers.

vtangjiemsft_2-1705993424829.pngvtangjiemsft_3-1705993442883.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

That's right, thank you very much for your help.😀

Sahir_Maharaj
Super User
Super User

Hello @Rai_BI,

 

Can you please try this DAX:

SellerGoals := 
VAR IsSeller1InContext = HASONEVALUE('Customers'[Seller code1])
VAR IsSeller2InContext = HASONEVALUE('Customers'[Seller code2])
VAR IsSeller3InContext = HASONEVALUE('Customers'[Seller code3])
RETURN
IF(
    IsSeller1InContext,
    CALCULATE(
        SUM('Goals'[GoalsValue]),
        USERELATIONSHIP('Customers'[Seller code1], 'Goals'[Seller code])
    ),
    IF(
        IsSeller2InContext,
        CALCULATE(
            SUM('Goals'[GoalsValue]),
            USERELATIONSHIP('Customers'[Seller code2], 'Goals'[Seller code])
        ),
        IF(
            IsSeller3InContext,
            CALCULATE(
                SUM('Goals'[GoalsValue]),
                USERELATIONSHIP('Customers'[Seller code3], 'Goals'[Seller code])
            ),
            SUMX(
                VALUES('Customers'[Seller code1]),
                CALCULATE(
                    SUM('Goals'[GoalsValue]),
                    USERELATIONSHIP('Customers'[Seller code1], 'Goals'[Seller code])
                )
            ) + SUMX(
                VALUES('Customers'[Seller code2]),
                CALCULATE(
                    SUM('Goals'[GoalsValue]),
                    USERELATIONSHIP('Customers'[Seller code2], 'Goals'[Seller code])
                )
            ) + SUMX(
                VALUES('Customers'[Seller code3]),
                CALCULATE(
                    SUM('Goals'[GoalsValue]),
                    USERELATIONSHIP('Customers'[Seller code3], 'Goals'[Seller code])
                )
            )
        )
    )
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Your measurement is basically working like the one I did. It is correctly calculating the individual values, but the total value is being calculated incorrectly.
I am attaching the example pbix file so that you can understand better.
File Download 

Rai_BI_0-1705870517113.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.