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

Days Remaining Calculation

Hello,

 

I am fairly new to DAX functions and i am trying to calculate a measure which gives me the number of working days remaining for a particular month or upto a particular date. All days except weekends are workdays.

 

I have 2 tables: an orders table where i have customers, quantity of axles to be shipped and the scheduled date of the shipment. I have a dim date table which i have joined to my orders table on the schedule date.

My main objective is to calculate a measure which will give the average axles to be made per working day, so i am just trying to divide the sum of quantity by the number of distinct working days that fall within a selected time frame.

 

The problem i face is when a particular customer has some past due scheduled shipment date against him.

e.g. if September 2018 is selected as a filter and Customer A has some quantity (say 50 axles) which were supposed to be shipped on 09/05/2018 and have not yet been shipped which makes it reflect in my orders table as past due, then my WorkingDays measure shows to be blank or zero and this makes my average_axles_per_day measure to be infinity. I guess this happens because when i select September 2018 and Customer A as filters my orders table is filtered to show only the data that matches the condition and it has only 1 scheduled shipment date which is past due.

 

So how do i get to show the WorkingDays measure to always show only the number of working days which are left in that particular time frame (so as of today 09/17/2018..my num of working days left in September 2018 should be 10). and my sum of past due quantity should be divided by this num of working days (in this case 50 divided by 10).

 

I appreciate any help provided.

Thank you.

1 ACCEPTED SOLUTION

Oh, that is because of the ALL in that formula. You might try changing that to ALLSELECTED and that might resolve it.

 

Measure 6 = 
VAR __today = TODAY()
VAR __max = MAX('Table14'[Schedule Date])
VAR __total = SUMX(ALLSELECTED(Table14),Table14[New Qty])
VAR __workdays = SUMX(FILTER(ALL('Calendar'),[Date]>=__today && [Date]<=__max),[IsWorkDay])
RETURN DIVIDE(__total,__workdays,0)

Or, you may have to use ALLEXCEPT. Or, you may just use SUMX(Table14,Table14[New Qty]) will depend on exactly what you are trying to do.


@ 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...

View solution in original post

12 REPLIES 12

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.