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
Anonymous
Not applicable

How to properly sum measures?Sum two measures

Hi everyone!

I'm trying to make a distinct count on a field on two tables that are not related. I'm making a distinct count and as a result, I have mesure1 for table1 and measure2 for table2 where if I group by customer I got a 1 for every customer in each table. Some cases measure1=1, measure2=0; measure1=0, and measure2=1 both cases it's ok because If I add the measures I get what I want (result=1). The problem is when I got measure1=1 and measure2=1 I add and get a 2 (I will be counting June customer twice) 

 

I made a third measure

 

Total  =
var Total = [measure1]+[measure2]
return
IF(Total=2;Total/2;Total)
 
but the result is not what I wanted
 
 PowerBIPowerBI
 
I want the sum of the Total column, not the sum of Total measure1 + Total measure2
 
Excel (Sum each column)Excel (Sum each column)
 
As I don't have the data in tables but both are measures I can't use HASONFILTER or COUNT ROWS or SUMX and I don't know what else to do
 
Thanks in advance for your help.
 
Best regards.
 
Mijalis
5 REPLIES 5
Greg_Deckler
Super User
Super User

Try something along the lines of:

 

Measure =

COUNTROWS(

  DISTINCT(

    UNION(

      SELECTCOLUMNS('Table1',"Column",[ColumnFromTable1]),

      SELECTCOLUMNS('Table2',"Column",[ColumnFromTable2])

    )

  )

)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
VijayP
Super User
Super User

Try to create another Tabel using Summarise function so that you can have the columns in one table with respective values so that you can use single measure (distinctcount) to get the result the way you want




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Anonymous
Not applicable

Hi thx for your reply

 

I used summarized and it worked perfectly.

 

Thank you very much!

 

Best regards,

 

Mijalis

az38
Community Champion
Community Champion

@Anonymous 

IF(Total=2;Total/2;Total)

this always will give 1 based on you data sample and Im pretty sure 74 is a good sum for your data

how is your data look like in original data source? what result do you expect?


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi, thx for the quickanswer.

 

I want 74 as a result, the problem is that power bi is giving 111, wich is the sum of total measure1 + total measure2. 74 will be the sum of the total column.

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.