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
kbol
Frequent Visitor

ALLEXCEPT Behavior - Appears To Retain Some Filters

Hi,

I've got a table of timesheet entries, each with an entry date, amount of hours, and several fields I want to slice on such as the type of time. I'm trying to write a measure that compares the amount of time with the selected criteria to all time within the selected range of entry dates - in other words, of all the time in the current date range, what percent has the sliced values?

My DAX is this:

 

 

Time Pct = VAR
    TotalTime = CALCULATE(
        [All Time],
        ALLEXCEPT(Timesheet, Timesheet[EntryDate])
    )
RETURN

DIVIDE(
    [All Time],
    TotalTime
)

 

 

 

where [All Time] is a previously-defined measure that sums different types of timesheet entries. Unfortunately, ALLEXCEPT does not seem to be removing all filters. 

I have a field called "timesheet group" on the Timesheet table with values [A-E]. I've separated out the numerator and denominator of Time Pct into separate measures. Without making any selections, the denominator - TotalTime - is correct at 360 for a specific date range. However, when I select a "timesheet group", it decreases to 359 for all values except for "D" (presumably the value of the offending hour?). I would have thought that ALLEXCEPT would cause the measure's calculation to ignore these selections.

Could someone help me find my misunderstanding?

 
1 ACCEPTED SOLUTION
kbol
Frequent Visitor

I did arrive at a solution. I don't know if this is the most idiomatic approach, but should anyone else stumble upon this thread later, here's what worked for me:

 

Time Pct = 
VAR
    DateStart = FIRSTDATE(DateCal[Date])
VAR
    DateEnd = LASTDATE(DateCal[Date])
VAR
    TotalTime = CALCULATE(
        [All Time],
        ALL(Timesheet),
        Timesheet[EntryDate] >= DateStart,
        Timesheet[EntryDate] <= DateEnd
    )
RETURN

DIVIDE(
    [All Time],
    TotalTime
)

Note that I'm now slicing on a general Date calendar that has a relationship to Timesheet on entry date. 

View solution in original post

6 REPLIES 6
v-kelly-msft
Community Support
Community Support

Hi @kbol ,

 

I singled out your measure of totaltime and you will see what misunderstood you:

If you put the measure together with the column of entry date in a table visual,you will see:

Annotation 2020-02-26 103323.png

But when you put the measure in a card visual,you will see:

 

Annotation 2020-02-26 103447.png

 

So you will find that your measure doesnt remove all the filters.If you want to remove all the filters,you'd better use the function "all" instead of "all except".

And your measure needs to be corrected to below:

 

Time Pct = VAR
    TotalTime = CALCULATE(
        [All Time],
        ALL(Timesheet)
    )
RETURN

DIVIDE(
    [All Time],
    TotalTime
)

 

 
Best Regards,
Kelly
 
Did I answer your question? Mark my post as a solution!

 

Greg_Deckler
Super User
Super User

Well, that might be because your All Time measure is adding them back in, what is the formula for that measure?


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

[All Time] is a sum of several measures all taking the form:

 

 

 

X Time = CALCULATE(
    SUM(Timesheet[Hours]),
    FILTER(
        Timesheet,
        (Timesheet[TimeType] = "XTypeString1" || Timesheet[TimeType] = "XTypeString2")
    )
)

 

 

 

Some of the measures apply additional filter criteria to the Timesheet entries, but they do this only by checking other fields on the row. I think it would be much more appropriate and flexible to label each entry in a calculated column and use [All Time] as a simple sum of hours, slicing on the calculated column. My plan is to do so once I get to refactor this report proper, but for now I've been vexed by troubles with this measure.

Thanks for the help so far.

Using ALL does not quite create the desired measure. I want to retain the overall date selection; there is a date range slicer on EntryDate and TotalTime should yield the sum of hours over this selected period. 

I do understand the problem a bit better now. While the measure would never be viewed this way, if I place the EntryDate and TimeLabel fields and the Denominator measure (TotalTime) with two days selected, I get values like:

EntryDateTimeLabelDenominator (TotalTime)
1/6/2018D1.00
1/5/2018A359.00
1/5/2018B359.00
1/5/2018C359.00
1/5/2018D359.00

... and so on. In fact, only first row has 1.00 for Denominator and all the others have 359. The correct value is 360. I need for the measure to evaluate to 360 for each row here, but not to the grand total of several hundred thousand hours across all Timesheet entries.

This need sounds a bit like ALLSELECTED on Timesheet[EntryDate] to me, but on its own this approach leads to the measure calculating subtotals for combinations of EntryDate + any other field. How can I modify this measure to produce the sum of hours in the entire selected period?

kbol
Frequent Visitor

I did arrive at a solution. I don't know if this is the most idiomatic approach, but should anyone else stumble upon this thread later, here's what worked for me:

 

Time Pct = 
VAR
    DateStart = FIRSTDATE(DateCal[Date])
VAR
    DateEnd = LASTDATE(DateCal[Date])
VAR
    TotalTime = CALCULATE(
        [All Time],
        ALL(Timesheet),
        Timesheet[EntryDate] >= DateStart,
        Timesheet[EntryDate] <= DateEnd
    )
RETURN

DIVIDE(
    [All Time],
    TotalTime
)

Note that I'm now slicing on a general Date calendar that has a relationship to Timesheet on entry date. 

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