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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
anonymous188
Regular Visitor

SUM based on measure is incorrect

Hi,

 

I have the following made-up tables:

 

Employee IDProduct Sold
111Banana
112Apple
112Kiwi
113Apple
113Kiwi
113Mango

 

Employee IDRole ID
1111
1121
1132
1141
1152

 

I'm trying to count the number of distinct products each employee has sold, but then multiply the number sold by 3 if their Role ID is 2 and by 1 if their Role ID is 1.  I'd like to create a chart within Power Bi with this information which would look like the following:

 

Employee IDBonus
1111
1122
1139
1140
1150

 

I was able to calculate this based on the following solution:

Counts = 
var cnt = Count(Table1[Product Sold])
return cnt * if(MAX(Table2[Role ID]) = 2,3, 1) 

 

However, now when I attempt to calculate the sum of the resulting column, all the counts are multiplied by 3, rather than just the rows corresponding to employees with specific Role IDs.

 

The following is the incorrect sum:

 

Employee IDCounts
1111
1122
1139
Total18
1 ACCEPTED SOLUTION

let's try this

 

add new column to get multiplier based on rold

 

m = 
var r = RELATED(Employee[Role ID]) 
return if(r=2,3,1) 

add a measure for count

Counts =  count(Sold[Product Sold])

add a measure for sum, multiple count with role multiplier 

 

product Sold Sum  = SUMX(Sold, [Counts]*Sold[m])

drop employee id and "product sold sum" measure in table visual and see if you get the result.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi @anonymous188,

 

Try this

 

1. Create a calculated column in the Role_ID table =if([Role ID]=1,1,3)

2. Create a relationship from the Employee ID column of the Data table to the Employee ID of the role_id table

3. In your visual, drag the Employee ID column from the role_ID column

4. Write the following measure

 

=DISTINCTCOUNT(Data[Product Sold])*MIN(role_id[Points])

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur,

 

Thanks for the help. I found that I needed to calculate the measure as

Count = DISTINCTCOUNT(ProductsSold[Product Sold])*MAX(Employees[Points])

with MAX instead of MIN to get the right answer.

Hi @anonymous188,

 

If my reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Vvelarde
Community Champion
Community Champion

@anonymous188

 

Hi, try with this measure;

 

Bonus2 =
SUMX (
    SUMMARIZE (
        Roles;
        Roles[Employee ID],
        "PSOLD"; IF (
            MAX ( Roles[Role ID] ) = 1,
            CALCULATE ( DISTINCTCOUNT ( 'Products Sold'[Product Sold] ) ),
            CALCULATE ( DISTINCTCOUNT ( 'Products Sold'[Product Sold] ) ) * 3
        )
    ),
    [PSOLD]
)

Regards

 

Victor

Lima - Peru




Lima - Peru
parry2k
Super User
Super User

Just answered on original thread Smiley Tongue

 

although good idea to start seperate thread.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I tried changing MAX to SUM in the Count measure, but now the sum is the normal sum before multiplying the counts (i.e. a total of 6). For reference, the following is how the measure is now calculated:

Counts = 
var cnt = Count(ProductsSold[Product Sold])
return cnt * if(SUM(Employees[Role ID]) = 2, 3, 1)

 

my bad, i just said sum without thinking, let me get back toyou



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

let's try this

 

add new column to get multiplier based on rold

 

m = 
var r = RELATED(Employee[Role ID]) 
return if(r=2,3,1) 

add a measure for count

Counts =  count(Sold[Product Sold])

add a measure for sum, multiple count with role multiplier 

 

product Sold Sum  = SUMX(Sold, [Counts]*Sold[m])

drop employee id and "product sold sum" measure in table visual and see if you get the result.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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