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
apup
Regular Visitor

Using ALLEXCEPT with DATESBETWEEN - Don't understand scope of ALLEXCEPT

Let's say I have a widget factory, and it produces different types of widgets. I would like a measure that returns the percentage of one type of widget produced against all types widgets produced, for the previous month. Evenually, I'd like a chart like this, which shows the percentage of the total (for that month, and a 12 month average) for each type (I've accidently put "6 month" instead of "12 month" in the pic, but you get the idea). 

 

image.png

 

Link to file: https://ufile.io/q8um7

 

I have this measure:

 

Widgets1Mth = DIVIDE(CALCULATE(COUNT(Widget[WidgetId]),DATESBETWEEN('Date'[Date],DATE(YEAR(TODAY()),MONTH(TODAY())-1,1),EOMONTH(TODAY(),-1))),CALCULATE(COUNTX(ALLEXCEPT(Widget,Widget[CreatedDate]),Widget[WidgetId]),DATESBETWEEN('Date'[Date],DATE(YEAR(TODAY()),MONTH(TODAY())-1,1),EOMONTH(TODAY(),-1))))

 

 But obviously I'm doing something wrong as it doesn't respect the DATESBETWEEN filter in the second CALCULATE function.

 

Can you please illuminate me on how to use these correctly?

 

I found a solution to my problem. I'm using these measures:

 

 

CountWidget = COUNT(Widget[WidgetId])
CountWidget as % = [CountWidget] / CALCULATE([CountWidget],ALL(Type[Type]))
CountWidget as % - 1 mth = CALCULATE([CountWidget as %],DATESBETWEEN('Date'[Date],EOMONTH(TODAY(),-2)+1,EOMONTH(TODAY(),-1)))
CountWidget as % - 12 mth = CALCULATE([CountWidget as %],DATESBETWEEN('Date'[Date],EOMONTH(TODAY(),-12)+1,EOMONTH(TODAY(),-1))

 

I can't post a pic as we're playing with the backend currently, but I'll post one shortly.

1 ACCEPTED SOLUTION

Hi @apup,

 

You may refer to my solution here.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

 

There is no mention of any date field in your dataset.  From just the image that you have shared, the DATESBETWEEN() function is obviously not required.  Can you share your dataset, the business question and the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I'm performing this calculation for a single month.

 

So the result I'm expecting is the table above. There were many widgets produced in other months, but I don't wish to include them in this calculation, hence I use the DATESBETWEEN filter.

 

 

Hi,

 

Try this

 

1. From the calendar table, drag the month field to the Visual filter section and select any month.  Ensure that there is a relationship from the date column in your base data to the date column in your calendar table

2. Try this calculated field formula

 

=SUM(Widget[Qty])/CALCULATE(SUM(Widget[Qty]),ALL(Widget[Widget Types]))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks Ashish, but the results are still incorrect.

 

I have changed your formula slightly to:

TESTWidgets% = COUNT(Widget[WidgetId])/CALCULATE(COUNT(Widget[WidgetId]),ALL(Widget[WidgetId]))

This results in all types returning 100%.

 

If I change the ALL clause to:

ALL(Widget))

Then the percentage is measured against all widgets, instead of those in the filtered month.

 

I have made an example in Excel (I made a typo, the "6 mnth" should be "12 mnth")

 

image.png

 

apup
Regular Visitor

Updated first post, hopefully more clearly.

Hi,

 

Share the link from where i can download your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Updated.

Hi @apup,

 

You may refer to my solution here.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.

Top Solution Authors