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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

FIltering max date

Hi,

 

For some reason I cannot filter sum so it only takes the biggest date. The measure returns me the whole total of all months, not the most recent one, not sure why. Any idea how I could fix that? Many thanks

CurrentWO = CALCULATE(sum('June WO`s'[Journal Amount]), FILTER(ALL('June WO`s'[Period]) , 'June WO`s'[Period] = MAX('June WO`s'[Period],'June WO`s'[Period])))

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Of course, it returns everything. FILTER is an iterator (do you know what that means?). This code

    FILTER (
        ALL ( 'June WO`s'[Period] ),
        'June WO`s'[Period] = MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )
    )

iterates all distinct values of 'June WO`s'[Period] and for each row calculates the condition:

'June WO`s'[Period] = MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )

What's the result of 

MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )?

Well, it's nothing else than

'June WO`s'[Period].

And what's the value of the condition

'June WO`s'[Period] = MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )?

Well, it's TRUE. ALWAYS, since 

'June WO`s'[Period] = 'June WO`s'[Period]

Hence, your filter does not filter anything. It returns all distinct values of 'June WO`s'[Period]. To understand code, I'd suggest you learn something about DAX.

 

Your code should probably be this:

CurrentWO =
var __maxPeriodInCurrentContext = MAX( 'June WO`s'[Period] )
var __result = CALCULATE ( SUM ( 'June WO`s'[Journal Amount] ),
'June WO`s'[Period] = __maxPeriodInCurrentContext )
return
__result

Please learn DAX. If you don't, you'll be producing numbers you will not be able to understand and will not know where they come from.

 

Best

Darek

 

 

Best

Darek

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Of course, it returns everything. FILTER is an iterator (do you know what that means?). This code

    FILTER (
        ALL ( 'June WO`s'[Period] ),
        'June WO`s'[Period] = MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )
    )

iterates all distinct values of 'June WO`s'[Period] and for each row calculates the condition:

'June WO`s'[Period] = MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )

What's the result of 

MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )?

Well, it's nothing else than

'June WO`s'[Period].

And what's the value of the condition

'June WO`s'[Period] = MAX ( 'June WO`s'[Period], 'June WO`s'[Period] )?

Well, it's TRUE. ALWAYS, since 

'June WO`s'[Period] = 'June WO`s'[Period]

Hence, your filter does not filter anything. It returns all distinct values of 'June WO`s'[Period]. To understand code, I'd suggest you learn something about DAX.

 

Your code should probably be this:

CurrentWO =
var __maxPeriodInCurrentContext = MAX( 'June WO`s'[Period] )
var __result = CALCULATE ( SUM ( 'June WO`s'[Journal Amount] ),
'June WO`s'[Period] = __maxPeriodInCurrentContext )
return
__result

Please learn DAX. If you don't, you'll be producing numbers you will not be able to understand and will not know where they come from.

 

Best

Darek

 

 

Best

Darek

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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