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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AlexisOlson
Super User
Super User

No CALCULATE Challenge -- Round #2b

@tamerj1 provided an ingenious solution to my No CALCULATE Challenge -- Round #2. However, I couldn't easily figure out how to adapt it to a situation where the measure is non-additive and the filtering I want to do is not a single value from a column.

 

In this case, I want to recreate this deceptively simple measure:

Distinct Orders (Non-China Benchmark) = 
CALCULATE (
    DISTINCTCOUNT ( Sales[OrderKey] ),
    Geography[RegionCountryName] <> "China"
)

For motivation purposes, assume China is an outlier in my data that I want to ignore for benchmarking purposes.

 

Note that this probably isn't something I'd use on its own. It would likely be used as a denominator in another measure like this:

Distinct Order Ratio =
DIVIDE (
    [Distinct Orders],
    CALCULATE (
        [Distinct Orders],
        Geography[RegionCountryName] <> "China"
    )
)


For full credit:

  1. CALCULATE and CALCULATETABLE are not allowed.
  2. The measure should work in any reasonable filter context, not just for the particular sample setup.
  3. Ideally, the measure should also be robust to model adjustments as discussed previously.

The primary goal is to find any solution.

The secondary goal is to find one that can be grokked by a non-expert.

 

Sample screenshot: 

AlexisOlson_0-1728675973085.png

Sample PBIX file attached.

Prior participants: @SharmaAntriksh@Greg_Deckler@CNENFRNL@ValtteriN

Other friends: @BA_Pete@bcdobbs@smpa01@parry2k

2 ACCEPTED SOLUTIONS

 

 

 inside a measure, 

 

Note that measures implicitly use CALCULATE, somewhat negating your premise.

 

Having said that, try this version

 

 

DONCB = 
VAR b = ADDCOLUMNS(ALL(Geography[RegionCountryName]),"do", [Distinct Orders])
RETURN SUMX(FILTER(b,[RegionCountryName]<>"China"),[do])

 

 

 

View solution in original post

tamerj1
Super User
Super User

@AlexisOlson 
Here is a solution using SUMMARIZECOLUMNS.

Distinct Orders (Non-China Benchmark) TJ = 
COUNTROWS (
    SUMMARIZECOLUMNS ( Sales[OrderKey], 
        FILTER ( 
            ALL ( Geography[RegionCountryName] ),
            Geography[RegionCountryName] <> "China" 
        ),
        "@Count", COUNTROWS ( Sales )
    )
)

1.png

However, applying the same filter over a higher cardinality column will reveal the difference with the SUMX solution provided by @lbendlin . DISTINCTCOUNT is non-additive calculation, which means SUMX will result in wrong results.

 

2.png

 

View solution in original post

24 REPLIES 24

Thanks for letting me know about the SummarizeColumns bug. We'll look into this.

 

 

 inside a measure, 

 

Note that measures implicitly use CALCULATE, somewhat negating your premise.

 

Having said that, try this version

 

 

DONCB = 
VAR b = ADDCOLUMNS(ALL(Geography[RegionCountryName]),"do", [Distinct Orders])
RETURN SUMX(FILTER(b,[RegionCountryName]<>"China"),[do])

 

 

 

@lbendlin@Dangar332 There's a visual level filter excluding a few countries, which accounts for the missing orders. It's working as intended even though it's a bit weird in this toy scenario.

HI, @AlexisOlson 

Measure for Not taking Order count of China which are use in another for Taking Total. 

Measure = 
 var a = 
COUNTROWS(SUMMARIZECOLUMNS(
		Sales[OrderKey],
		FILTER(
			VALUES(Geography[RegionCountryName]),
			Geography[RegionCountryName] <> "China"
		),"sf",COUNTROWS(Sales)
	))
 RETURN
a


Measure for Distinct Order (Non-China Benchmark)

Distinct Order (Non-China Benchmark)_Dangar= 
SUMX(
  ALL(
    Geography[RegionCountryName]),
    [Measure]
  )


Retio

Distinct Order Ratio_ = 
DIVIDE([Distinct Orders],[Distinct Order (Non-China Benchmark)_Dangar])

 

Dangar332_0-1728720107809.png





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.