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

Calculate ALL regardless of slicer

Hi Everyone - Very new to PowerBI so pardon my ignorance - I am sure there is an easy solve for this!

 

I am trying to create a new column/measure that will calculate all orders regardless of my slicer.

 

For example, when the slicer is selected for Washington DC I have three values in the graph.  I want the third value (pink line) to show ALL orders, not just Washington DC orders.

 

Capture.PNG

 

I have tried the following to create a new column/measure:

 

AllOrdersAvg = CALCULATE(AVERAGE(AllMonths[Orders]);ALLSELECTED(AllMonths))

 

But receive the following error:

 

The syntax for ';' is incorrect. (DAX(CALCULATE(AVERAGE(AllMonths[Orders]);ALLSELECTED(AllMonths))))

 

Also tried:

 

AllOrdersAvg = ALL(AllMonths[Orders])

 

But received the following error:

 

A table of multiple values was supplied where a single value was expected.

 

What am I doing wrong???

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

to remove the existing filter that comes from the slicer try this measure:

 

Measure 4 = 
CALCULATE(
    AVERAGE('AllMonths'[Orders])
    ,ALL('AllMonths'[name of the column that contains "Washington DC"])
)

Please be aware that the character that separates arguments inside function depends on your language settings, if you have an english os the above formula should work, but maybe you have to use ;ALL use a semicolon instead of a comma.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

One of the most important things in DAX is the concept of filters.  When you put data into a chart/table/ect, there are filters.  That is why you get a different answers.  With ALL you want to tell DAX to ignore the current filter and use an entire table or an entire column.  A good practice is to never filter an entire table if you can filter a column.  

 

So using the Contoso DB as an example:

1) Create a base measure (which looks like is a count or sum of orders)

 

Total Sales = SUM ( Sales[Unit Price] )

2) Create a measure, using the base measure, that will give you the total regardless of what is selected in a slicer, or what other filter context exist:

 

 

All Sales = 
CALCULATE(
	[Total Sales],
	ALL ('Product'[Brand],'Product'[Color])
)

So in this example, ALL ignores the filters from the Product Table of Brand and Color. Any other columns will not be ignored, and that filter context will be used to evaluate Total Sales. There is also ALL's cousin, ALLEXCEPT. Output with Product and Color on rows:

 

Product Color ALL example.png

 

ALLSELECTED is an interesting function.  It works like you would expect, most of the time.  It actually removes the current filter context and restores the previous one.  That's a gross oversimplification, but something to keep in mind and maybe explore further.  

 

All Sales, of only Selected =
CALCULATE(
	[Total Sales]
	ALLSELECTED ('Product'[Brand],'Product'[Color])  /*Can Also use ALLSELECTED(), which uses the whole data model*/
)

All Selected Example.png

 

Hope that helps

 

TomMartens
Super User
Super User

Hey,

 

to remove the existing filter that comes from the slicer try this measure:

 

Measure 4 = 
CALCULATE(
    AVERAGE('AllMonths'[Orders])
    ,ALL('AllMonths'[name of the column that contains "Washington DC"])
)

Please be aware that the character that separates arguments inside function depends on your language settings, if you have an english os the above formula should work, but maybe you have to use ;ALL use a semicolon instead of a comma.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

@TomMartensMany thanks this worked amazingly well and easy; I would have never been able to figure it out myself.  Thank you!

 

And @Anonymous this looks like a good solution too - thanks!  I will definitely keep it in mind for future reference!

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.