1

in power bi I have following table, I want to calculate the total keywords from the table below. Ids are replicating because they are coming from some other Stored Procedure. I want sum to be like this 12+13+14.

Id  Keywords
A   12
B   13
B   13
B   13
B   13
C   14
C   14
B   13
A   12
C   14
C   14
C   14
C   14
A   12
A   12
B   13
A   12
B   13
A   12
B   13

I tried X = SUMX(FILTER(Query1,DISTINCT(Query1[Id])),[Keywords]) and X = CALCULATE(SUM(Query1[Keywords]), FILTER(Query1, DISTINCT(Query1[Id]))) But nothing is coming.

How this can be done?

1 Answer 1

2

Try, for example:

X =
SUMX ( SUMMARIZE ( Query1, Query1[Id], Query1[Keywords] ), [Keywords] )

This relies on a 1:1 relationship between Id & Keywords. (If A could sometimes be 12, and sometimes be 13, the above will include both A-12 and A-13.)

Modifying your query to only bring in a distinct set would be ideal, rather than using DAX to de-dupe after the fact. If you're using Power Query, for example, you can remove duplicates as the data is being imported even though your stored procedure is sending them (and simplify your DAX expressions). From your canvas, Home > Edit Queries > Edit Queries. Then select the last step (in my screenshot it's Changed Type) and choose, Home > Remove Rows > Remove Duplicates.

enter image description here

Or ideally, update the stored procedure to not send duplicates (although I realize that might be out of your control).

Sign up to request clarification or add additional context in comments.

3 Comments

I know it will be out of my question's scope, but can you explain how this works?? (SUMX & SUMMARIZE)
Can you please help me with this stackoverflow.com/questions/44884315/…
SUMMARIZE is similar to a GROUP BY clause in SQL. In this example, it says "make a table from Query1 with only the unique combinations (distinct values) of Id & Keywords". The SUMX says "sum the Keywords column from the SUMMARIZE table. SUMX is necessary because I want to specify what table the column Keywords is in: my SUMMARIZE table, not the Query1 table. More information about SUMMARIZE: msdn.microsoft.com/en-us/library/gg492171.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.