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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JacobCoops
Frequent Visitor

Measure for counting ignoring context filters

Hello,

 

I want to (distinctly) count how many stores have participated in the delivery of an order. I want the measure to ignore the specific filtercontext for the calculations only and not for the visual itself. The model is a Direct Model on an Analysis Service using a Star Scheme. An example of the data:

JacobCoops_1-1639490241619.png

 

In the above picture i want it to write 3 on every row whilst only showing the 3 stores in question. Using AllExcept, ALLSELECTED etc. either does the same as the picture or counts every single "Store No." in the dataset. What i want is to tag every "Order No." with the number of unique "Store No.".

 

In SQL i would do it like in the picture below, but i do not know how in DAX.

JacobCoops_3-1639491254184.png

 

Any help would be appreciated!

 

 

1 ACCEPTED SOLUTION

Hi @JacobCoops ,

According to your description, Order No and Store No are in different tables, I create a sample, they have relationship by the Key column.

vkalyjmsft_1-1640929274320.png

Here's my solution, create a measure.

Measure =
CALCULATE (
    DISTINCTCOUNT ( 'Store'[Store No] ),
    FILTER ( ALL ( 'Order' ), 'Order'[Order No] = MAX ( 'Order'[Order No] ) ),
    FILTER ( ALL ( 'Store' ), 'Store'[Key] = MAX ( 'Store'[Key] ) )
)

Get the expected result.

vkalyjmsft_2-1640929582878.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

11 REPLIES 11
CNENFRNL
Community Champion
Community Champion

SELECT [OrderNr] ,
       [LagerNr] ,
       COUNT([LagerNr]) OVER (PARTITION BY [LagerNr]) [#DIST]
FROM XXX
WHERE [OrderNr] = '12345'
GROUP BY [OrderNr] , [LagerNr]

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

smpa01
Super User
Super User

@JacobCoops  the equivalent dax is following

 

smpa01_0-1639492082986.png

 

 

Measure = CALCULATE(COUNT('Table'[storeNumber]),ALLEXCEPT('Table','Table'[orderNumber]))

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi,

 

That return the following (there can be multiple rows per "Order No." and "Store No." combination which i eliminate using the group by in the SQL)

JacobCoops_0-1639493290678.png

 



@JacobCoops  can you try this

Measure = CALCULATE(DISTINCTCOUNT('Table'[storeNumber]),ALLEXCEPT('Table','Table'[orderNumber]))

 

smpa01_0-1639493623624.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi,

This is where it gets strange. I would expect your suggestion to work, but i returns the following. Do you think my model i messed up?

JacobCoops_0-1639494646365.png

 

Hi @JacobCoops ,

I notice the Order No and Store No are not in the same table in your formula, is there Order No column in the Store table? You should use the same table in the formula, it will work fine.

Dilivered from stores# = CALCULATE(DISTINCTCOUNT('Sotre'[Store No]),ALLEXCEPT('Sotre','Sotre'[Order No]))

vkalyjmsft_0-1639731280320.png

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

Correct, they are not in the same table. They are connected via. the fact where i join them on their respective keys.

I have tried to distinctcount on the keys in the fact table, but that is not yielding the correct results either.

Hi @JacobCoops ,

According to your description, Order No and Store No are in different tables, I create a sample, they have relationship by the Key column.

vkalyjmsft_1-1640929274320.png

Here's my solution, create a measure.

Measure =
CALCULATE (
    DISTINCTCOUNT ( 'Store'[Store No] ),
    FILTER ( ALL ( 'Order' ), 'Order'[Order No] = MAX ( 'Order'[Order No] ) ),
    FILTER ( ALL ( 'Store' ), 'Store'[Key] = MAX ( 'Store'[Key] ) )
)

Get the expected result.

vkalyjmsft_2-1640929582878.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@JacobCoops  can you please provide some sample data please?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi, 

 

I can't upload files to this thread. Do you have any suggestions to how i can send it?

@JacobCoops  can you please upload a pbix in g/1 drive or any other file hosting service and share the link here?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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