cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MikeSwe
New Member

Multiplying distinct count with related table

Hi,

 

I am new to PowerBI and have been trying to solve the below. However after searching various forums without luck I thought to ask if someone could help with the below.

 

We have a table (main_table) with "unique names", grouped by "project", "site" and "site category".

UniqueNames

ProjectSiteSiteCategory
Name 1Project XA10
Name 2Project XA11
Name 3Project XA10
Name 4Project YB13
Name 5Project YB13

 

By using a table and count the unique values of "Site Category" per Project I managed to produce the below output.

ProjectSiteNbr. Unique Site Category
Project XA2
Project YB1

 

In a different table (cost) there is a value and a cost associated with each site.

SiteCostValuePrice
A2100
B1150

 

The goal is to produce a table/graph multiplying the unique site categories per project with the related cost table based on site, CostValue and Price ("Nbr. Unique Site Category" x "CostValue" x "Price").

E.g. Project X =  2 x 2 x 100, Project Y = 1 x 1 x 150

 

ProjectCost
Project X400
Project Y150

 

A relationship has been setup between the two tables with "Site" as the linked column.

 

By using a measure with DISTINCTCOUNT('main_table'[SiteCategory]) I have managed to get the number of unique SiteCategory but multiplying this with the cost table does not work since it does not do this per site.

 

Any pointers in the right direction?

1 ACCEPTED SOLUTION

I tried that but it did not work as the top row should give value 200.

However we solved it by adding a calculated column to the main table with the cost value  and price added per row. The muliplication still did not work at first, due to one data being aggregated and the other were not. However using MAX did the trick and the data is presented correctly.

Thanks!

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@MikeSwe , You need something like 

 

Sumx(Summarize(main_table, main_table[Project], main_table[Site], "_1", DISTINCTCOUNT('main_table'[SiteCategory]), "_2", related(cost[CostValue]) , "_3", related(cost[Price]) ), [_1], [_2], [_3])

 



Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || Learn 50+ Power Query List Functions
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!

Capture1.PNGHi @amitchandak ,

When trying to apply this I get an error message stating that there are too many arguments for Sumx and that two arguments is the maximum.

Hi @MikeSwe ,

 

If you have created the following relationship, then I think you can try the measure.

 

vkkfmsft_0-1642732979381.png

Measure = [Nbr. Unique Site Category] * SUM(cost[Price]) * SUM(cost[CostValue])

vkkfmsft_1-1642732999597.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

I tried that but it did not work as the top row should give value 200.

However we solved it by adding a calculated column to the main table with the cost value  and price added per row. The muliplication still did not work at first, due to one data being aggregated and the other were not. However using MAX did the trick and the data is presented correctly.

Thanks!

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.