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
rolf1994
Helper II
Helper II

Calculated total showing the wrong number in directquery

Hi, I am trying to calculate the following:

 

Measure

DistinctQuantity = CALCULATE(DISTINCTcount([Id]),[IsActive]="Active")

Measure

TotalPrice= DistinctQuantity*sum(Price)
My data looks like this:
        Price       DistinctQuantity   TotalPrice
A 10 1 10
B 0 100 0
C 0 899 0
Total 10 1000 10000
 
 
 
I want mu table to show a total of "10" but instead it shows 10000. I want to add a column with the distinctquantity but I am working in DirectQuery so i cannot use the Calculate function to add a calculated column. How can I fix this?
1 ACCEPTED SOLUTION
v-sihou-msft
Employee
Employee

@rolf1994

 

In this scenario, you TotalPrice should be eavaluated on each row level, so you should use SUMX() function.

 

Total Price = SUMX(Table3,Table3[Price]*[Total Quantity])

55.PNG

 

 

Regards,

View solution in original post

2 REPLIES 2
v-sihou-msft
Employee
Employee

@rolf1994

 

In this scenario, you TotalPrice should be eavaluated on each row level, so you should use SUMX() function.

 

Total Price = SUMX(Table3,Table3[Price]*[Total Quantity])

55.PNG

 

 

Regards,

Greg_Deckler
Super User
Super User

In general, consider that the total line is really the measure evaluated in the context of ALL. You can add a if HASONEFILTER to your measure to calculate it for rows with the alternative being your calculation for your total row. I may have those reversed. It's early.


@ 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...

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.