cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sanvdrie Visitor
Visitor

Create a measure that calculates sum of distinct values over multiple columns in a table

My table has following structure:

Knipsel.PNG

 

In this table, if a combination of country and case have multiple weapons involved, the value shall be contained in those multiple rows(for example the 200 in row 2 and 3 here). However, I want to be able to create a table visual that gives the sum of the value per country, taking into account that only the distinct values per country and case should be summed up.

Table should look like this:

Germany 300

Belgium 200

Netherlands 100.

I'd like to use a calculated measure for this, but not sure how to code it. Can someone help me?
Regards,
Sander

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
CheenuSing Super Contributor
Super Contributor

Re: Create a measure that calculates sum of distinct values over multiple columns in a table

Hi @Sanvdrie 

 

Try this

 

Totals =
SUMX (
    SUMMARIZE (
        Country,
        Country[Country],
        Country[Case],
        "Value", DISTINCT ( Country[Value] )
    ),
    [Value]
)

Replace Country by your tablename.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
vanessafvg Super Contributor
Super Contributor

Re: Create a measure that calculates sum of distinct values over multiple columns in a table

@Sanvdrie  hi can you explain the rule a bit better, why for germany is it only 300 and not 400?  there doesnt seem to be a clear rule for which row you want if there is more than one.


Did I answer your question? Mark my post as a solution.
Proud a to be a Datanaut!
Highlighted
CheenuSing Super Contributor
Super Contributor

Re: Create a measure that calculates sum of distinct values over multiple columns in a table

Hi @Sanvdrie 

 

Try this

 

Totals =
SUMX (
    SUMMARIZE (
        Country,
        Country[Country],
        Country[Case],
        "Value", DISTINCT ( Country[Value] )
    ),
    [Value]
)

Replace Country by your tablename.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

View solution in original post

CheenuSing Super Contributor
Super Contributor

Re: Create a measure that calculates sum of distinct values over multiple columns in a table

Hi @Sanvdrie ,

 

I forgot to add the following lines.

 

Now create a table visual with Country and Totals

 

You will get your desired result.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 6 members 1,837 guests
Please welcome our newest community members: