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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

DAX to calculate a total

Hello folks

I have 2 tables, a date table and a work order table.

I want to calculate the sum of a field called 'Total', from the work order table.

However I only want it to sum the values based on the MAX date in a field 'date first completed' in the work order table. 

Additionally though I want it to sum all the values in that week, based on the field 'start of week' from the date table.

There is an inactive relationship between 'date' in the date table and 'date first completed' in the work order table.

What sort of DAX measure would I need for this please I'd be ever so grateful for any suggestions.

 

Thanks

Ian

 

 

 

 

 

10 REPLIES 10
Anonymous
Not applicable

Bumping this for some assistance

Ashish_Mathur
Super User
Super User

Hi,

Share some data and show the expected result.


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

@Anonymous Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Please see the attached images of example tables - the Date Table is the one in my model and the other is just an example of the 2 columns I am referencing.

 

In the Work Order table the MAX 'date first completed' will never be greater than yesterday's date.  So, no matter what day of the week it is today I would like to sum the 'Net Total' column right the way back to the 'Start of Week' from the date table - where the 'Start of Week' corresponds to MAX of 'Date First Completed'.

 

E.g. today I would like the values summed from 23rd January onwards (i.e. the 'Start of Week' value that corresponds to the 'Date First completed')

 

however were the MAX value of 'Date First Completed' the 17th January then I would like all values summing from the 16th January onwards.

 

I hope this is clearer and appreciate the assistance!DateTable.pngWorkOrder.png

 

Here's a calculation that seems to be what you are looking for:

https://blog.enterprisedna.co/calculate-previous-weeks-sales-advanced-dax-in-power-bi/

Padycosmos_0-1674913297812.png

 

Anonymous
Not applicable

Sadly this didn't work either 

Anonymous
Not applicable

Hi, thank you so much for the reply!

 

This doesn't work sadly....it returns a much much higher value than anticipated...

Could you please try using ALLSELECTED() instead of ALL()

Anonymous
Not applicable

Thank you; this didn't work either.  I've posted some screen shots of the items so hopefully that helps.  Thank you so much for your assistance!

Padycosmos
Solution Sage
Solution Sage

Hope this helps

SUMX(
FILTER(
ALL(WorkOrder),
MAX(WorkOrder[date first completed]) >= MIN(Date[start of week]) &&
MAX(WorkOrder[date first completed]) <= MAX(Date[start of week])
),
WorkOrder[Total]
)

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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