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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
trine_norris
Frequent Visitor

Optimizing the allexcept function

Hi, 

 

I have some data (Record ID and Key) and two measures (Selected and Max), which currently looks something like this:

 

Record IDKeySelectedMax
1uniquekey1 0,67
1uniquekey2 0,67
1uniquekey30,670,67
1uniquekey40,420,67
1uniquekey5 0,67
1uniquekey6 0,67
1uniquekey7 0,67
1uniquekey8 0,67
1uniquekey9 0,67
1uniquekey100,340,67
1uniquekey11 0,67
1uniquekey12 0,67
1uniquekey13 0,67
2uniquekey1 0,45
2uniquekey2 0,45
2uniquekey30,330,45
2uniquekey40,450,45
2uniquekey5 0,45
2uniquekey6 0,45
2uniquekey7 0,45
2uniquekey8 0,45
2uniquekey9 0,45
2uniquekey100,340,45
2uniquekey11 0,45
2uniquekey12 0,45
2uniquekey13 0,45

 

"Selected" currently highlights a value of the Key's that are actively selected. 

Instead "Max" finds the maximum "Selected" value, grouped by Record ID's. It is defined like this:

 

Max = calculate([Selected]; ALLEXCEPT(Table, Table[Record ID]))

 

This solution works - however it is a major problem, that this max function does not ignore the rows without any Selected value. This is because the data set is about one billion rows long. Is there any way to get this functionality without including the deselected Keys?

Thanks in advance!

 

 

 

 

11 REPLIES 11
Anonymous
Not applicable

Can you please show me your [Selected] measure?

I suspect you are talking about calculated columns here, not measures.

Best
D

Hi Darlove, 

 

There are no calculated columns in my example, even though it is displayed like it.

 

My selected measure looks something like this:

 

Selected = calculate( max( Table[Value] ),
                  filter( Table[Key] in Union(

                  values(Table1[Key]), 

                  values(Table2[Key]),

                  values(Table3[Key])....

)))

 

So basically i have many slicers selecting which rows should be active. As it is a big dataset, one slicer cannot make all the selections, and still make sense for the use. So I cannot make an active relationship in the Data Model.

 

To elaborate, i have many tables in which the user can select slicers to define which row should be active. So each table returns one row or one key based on the slicer selection. These are then highlighted by Selected.

Anonymous
Not applicable

First, try to change the measure to:

Selected =
var __allSelectedValues =
	Union(
	  values(Table1[Key]), 
	  values(Table2[Key]),
	  values(Table3[Key]),
	  ... // however many you need to put in here
	)
var __result =
	calculate(
		MAX( Table[Value] ),
		KEEPFILTERS(
	        TREATAS(
	        	__allSelectedValues,
	        	Table[Value]
	        )
	    )
)
return
	__result

 

Without relationships this is the fastest code you can get (TREATAS).

 

Best

D

Anonymous
Not applicable

If your table with billions of rows is the one above... then how are you presenting it to the end user? Are you slicing by Record Id as well to just show a couple of Record Id's?

This whole stuff seems to me to be a bit fishy... If there's a big table and you're creating a measure for it that needs to use CALCULATE, then it'll be slow as hell because of the number of context transitions that need to take place.

Best
D
Greg_Deckler
Community Champion
Community Champion

Perhaps:
Max =
VAR __Max = calculate([Selected]; ALLEXCEPT(Table, Table[Record ID]))
RETURN IF(ISBLANK([Selected]),BLANK(),__Max)


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

It now returns the right thing, but is not really quicker, as it still calculates on all rows in the variabel.

 

I was thinking that something like:

Max = Calculate(Selected, distinct(Record ID))

should work, but of course that syntax is invalid.

OK, try this, this should be faster:
Max =
IF(ISBLANK([Selected]);BLANK();
calculate([Selected]; ALLEXCEPT(Table, Table[Record ID])))


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

This might be even better:

 

Max =
IF([Selected]=BLANK());BLANK();
calculate([Selected]; ALLEXCEPT(Table, Table[Record ID])))



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I just posted an article on DAX performance tuning that might help:

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, 

 

Thanks for your replies, though unfortunately they only slow the measure down. 

I was hoping for way to use allexcept with a filter.

Anyone? 🙂

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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