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
RemiAnthonise
Helper V
Helper V

Calculate SUM where Date = MAX

Hi guys,

 

I couldn't find the right answer, maybe you can help me.

 

I've got a table, see image below. It's possible that salary, bonus etc gets updated so I want to calculate with the most recent record of it. In this case, with the MAX ValidFrom.

For example, I want to calculate the salary:
maxdatasalaris.jpg

 

Salaris = [Factor opslag] * CALCULATE(SUM(WorkerPositionEarningCodes[Amount]); WorkerPositionEarningCodes[EarningCodeId] = "Salaris" && MAX(WorkerPositionEarningCodes[ValidFrom])) All text in my formula written in black is allright. So the red part gives me the following error:

 

"A function ‘CALCULATE’ has been used in a true-false expression that is used as a table filter expression. This is not allowed."

How can I solve this? Or this isn't the right way?

Thanks in advance!

1 ACCEPTED SOLUTION

Hello @RemiAnthonise,

 

This can be restructured as:

 

Salaris = [Factor opslag] * CALCULATE(SUM(WorkerPositionEarningCodes[Amount]); WorkerPositionEarningCodes[EarningCodeId] = "Salaris"; FILTER(WorkerPositionEarningCodes,WorkerPositionEarningCodes[ValidFrom]=MAX(WorkerPositionEarningCodes[ValidFrom])))

 

Hope this works.

 

Regards.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

You miss something, after the max.

 

you should reference the fgact table (code), like:

 

&& 'FactTable'[ID] = MAX('DimTable'[ID])

I hope I'm seeing things clearly here.

Hello @RemiAnthonise,

 

This can be restructured as:

 

Salaris = [Factor opslag] * CALCULATE(SUM(WorkerPositionEarningCodes[Amount]); WorkerPositionEarningCodes[EarningCodeId] = "Salaris"; FILTER(WorkerPositionEarningCodes,WorkerPositionEarningCodes[ValidFrom]=MAX(WorkerPositionEarningCodes[ValidFrom])))

 

Hope this works.

 

Regards.

Thankks @rajulshah ! I'm happy with the result.

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