Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JuanSombrero023
Regular Visitor

Distinctcount + sumx throws strange results

Hi All,

 

I have been breaking my head around this one, hope somebody can help me understand. I have an issue with a Dax formula, I hope you don't mind I added an example in Excel PowerPivot rather than PBI...

 

Attached file contains data sample, 1 measure and a pivot table.

 

Result is as follows:

JuanSombrero023_1-1725061785280.png

 

Can  somebody explain me the 122...I would totally expect 92 there...I am aware of how SUMX works, I am aware that totals are not always a sum of the above, and I feel like I am missing the obvious here, but I think I am in somewhat of a rabbit whole here 😉
Who can help me undertand.

Book1.xlsx

For the grand total, I would expect that VALUES(PropertyID) iterates over Property 1, counts 61 distinct dates...then Property 2, counts 31 disntinct dates, then sums them to 92...

 

Thx

Jan

1 ACCEPTED SOLUTION
JuanSombrero023
Regular Visitor

Appreciated alot man!

View solution in original post

2 REPLIES 2
JuanSombrero023
Regular Visitor

Appreciated alot man!

OwenAuger
Super User
Super User

Hi @JuanSombrero023 

Change your measure to:

Measure 1:=
SUMX (
    VALUES ( Table1[Occupancy_Data[PropertyId]]] ),
    CALCULATE (
        DISTINCTCOUNT ( Table1[Occupancy_Data[DateKey]]] )
    )
)

 

The short explanation is that in this case you need to wrap the 2nd argument of SUMX in CALCULATE to trigger "context transition". This converts the row context of the first argument of SUMX into equivalent filter context.

 

Without CALCULATE, with the PivotTable you have created, you won't see any difference on the rows of the PivotTable since each row's filter context is a single PropertyID already. However, at the total level, each iteration of SUMX has the same filter context (both PropertyID values) and ends up adding 61 DateKey values twice, giving 122 as the result.

 

See these articles for more explanation:

https://www.sqlbi.com/articles/understanding-context-transition-in-dax/

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.