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

DAX Calculation Help with filters on visual

I have the following data, by day. this is an example of Multiple days data. 

 

Momentcall_idcall_time
Widget b45091055171665904/15/2021
Widget a45052815198781404/15/2021
Widget b45052815198781404/15/2021
Accessory a48251648875560904/15/2021
Widget a45104852083015604/16/2021
Widget b45104852083015604/16/2021
Accessory a45102819691069404/16/2021
Widget b45102819691069404/16/2021
Battery45239660704563204/17/2021

 

and I need to show a filtered selection of products on a visual and the % they show up vs all products. For example I would like to show the following where Widget b and Battery are filtered out on the visual filter, but the total orders still shows 9 so my Occerance % is the same and doesn't re-calcuate based on the visible products. 

 

producthow many timestotal items ordered% on order 
Widget b4944% 
Widget a2922% 
Accessory a2922% 
Battery1911% 

 

now if I use a filter to just select say 4/15 I would expect the result to be like this

producthow many timestotal items ordered% on order
Widget b2450%
Widget a1425%
Accessory a1425%
Battery040%

 

I've been trying to use the ALLEXCEPT but it's not working the way I thought it would. 

total orders =
CALCULATE(DISTINCTCOUNT(ordertable[order_number]), ALLEXCEPT(ordertable, ordertable[date]))
 
how do I count the total when I have a visual filter, so that I ignore the visual filter and get the total of 9 in this example?
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Anonymous,

 

Accoriding to my understanding, you want to get dynamic count and percentage based on selected values in slicer(Moment and Date), right?

 

I have done it with creating a new table using the following formula:

NewTable = DISTINCT(SELECTCOLUMNS('Table',"Product",[Moment]))

 new table with product.PNG

Then please try these:

how many times = IF(MAX('NewTable'[Product]) in ALLSELECTED('Table'[Moment]),CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Moment]=MAX('NewTable'[Product]))),0)+0
total items = CALCULATE(COUNTROWS('Table'),FILTER('NewTable','NewTable'[Product] =MAX('Table'[Moment])))
% on order = DIVIDE([how many times],[total items])

The final output is shown below:

dynamic count and percentage.gifBest Regards,
Eyelyn Qin
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

16 REPLIES 16
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-eqin-msft
Community Support
Community Support

Hi @Anonymous,

 

Accoriding to my understanding, you want to get dynamic count and percentage based on selected values in slicer(Moment and Date), right?

 

I have done it with creating a new table using the following formula:

NewTable = DISTINCT(SELECTCOLUMNS('Table',"Product",[Moment]))

 new table with product.PNG

Then please try these:

how many times = IF(MAX('NewTable'[Product]) in ALLSELECTED('Table'[Moment]),CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Moment]=MAX('NewTable'[Product]))),0)+0
total items = CALCULATE(COUNTROWS('Table'),FILTER('NewTable','NewTable'[Product] =MAX('Table'[Moment])))
% on order = DIVIDE([how many times],[total items])

The final output is shown below:

dynamic count and percentage.gifBest Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

so I wouldn't want the total items to change with the item filter, just with the date filter. 

 

so for example with 4/15 and 4/16 sleceted and  Accessory a selected I would see

 

Accessory A

how many times = 2

total item = 8

Not the best at this, but you could try:


total orders = SUMX ( ALLEXCEPT(ordertable, ordertable[call_time]), DISTINCTCOUNT( ordertable[call_id] ) )

gdarakji
Resolver III
Resolver III

Your measure looks correct. Could it be that you have dimension tables impacting the filter context? Anyway, you can try the below measure:

TotalOrders = CALCULATE(DISTINCTCOUNT('Table'[Order_Number]),ALL('Table'[Product]))
Anonymous
Not applicable

@gdarakji I took off all the extra tables from my model, now it's just the one table. it has product, order_number, and Date. 

 

when I use the following

TotalOrders = CALCULATE(DISTINCTCOUNT('Table'[Order_Number]),ALL('Table'[Product]))

 

it's only counting those products that are showing, I have a filter on the product under the "filters on this visual" , then I have a slicer for the date to show a single or date range.

 

shouldn't ALL ignore the visual filter?

selimovd
Super User
Super User

Hey @Anonymous ,

 

I would try it with the following measures:

The amount of orders:

Amount Orders = COUNTROWS( ordertable )

 

The total orders: 

Total Orders = CALCULATE( COUNTROWS( ordertable ), ALL( ordertable ) )

 

And then the ocurrence as percentage:

Occurrence = DIVIDE( [Amount Orders], [Total Orders] )

 

This is creating the following result:

selimovd_0-1621372723854.png

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Anonymous
Not applicable

@selimovd this is close but Ideally I would show just Accessory 1 and widget 1 on the table output. using a visual filter to exclude widget 2 and Battery. when I filter to just one or two of the products then the count is only reflecting those items and not the toal.

Hey @Anonymous ,

 

what do you want to be different?

If you select 2 products the numbers adapt to these two products:

selimovd_0-1621431970151.png

 

The numbers for Accessory 1 and widget 1 stay the same, the total adapts to the selected products.

Can you tell me specifically how you would like the result to be?

 

Best regards

Denis

 

 

Anonymous
Not applicable

@selimovd 

 

so when I use CALCULATE( COUNTROWS( ordertable ), ALL( ordertable ) )

 

I get the count of rows on the total table, however it's not working when I apply a date slicer to the data to look at an indiviual day. 

Anonymous
Not applicable

@selimovd @gdarakji 

Updated the original post to include date since that seems to be the issue. 

 

 

Hey @Anonymous ,

 

please explain detailed what you want.

Show us your data model, tell us what are you filtering and what do you expect the result to be.

Make it as easy as possible for us to help you, we cannot know what your scenario is when you don't describe it properly...

 

Best regards

Denis

Anonymous
Not applicable

Thanks @selimovd  for all the help, I just updated the main post. I think that added date context should help. 

 

Momentcall_idcall_time
Widget b45091055171665904/15/2021
Widget a45052815198781404/15/2021
Widget b45052815198781404/15/2021
Accessory a48251648875560904/15/2021
Widget a45104852083015604/16/2021
Widget b45104852083015604/16/2021
Accessory a45102819691069404/16/2021
Widget b45102819691069404/16/2021
Battery45239660704563204/17/2021

 

should show the following with a slicer on date for 4/15

producthow many timestotal items ordered% on order
Widget b2450%
Widget a1425%
Accessory a1425%
Battery040%

Hey @Anonymous ,

 

no, it doesn't. I still don't know the relationship and what you expect as a result.

Please add that.

 

Best regards

Denis

Anonymous
Not applicable

@selimovd the table is very simple, just product, order_id and date. 

 

I need to be able to look at the total count of items, count by indiviual item, and filter than by date with a slicer. 

example1.JPGexample2.JPG

 

 

@Anonymous  how is the relationships with these tables?

Can you share the file?

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.