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
curiouspbix0
Helper IV
Helper IV

Working Day Calculations - DAX function help to work around scalar value

Hello Geeks,

 

Hitting roadblocks on dax here on trying to compute work day computations, see screen print below. Any help/ideas is appreciated.

Requirement - Two tables, Table 1- Transactional Data Table 2 - Working Day List

Expected Outcome - Combine these two tables to compute measure - Products Received for a given order date and Order Received Date Business Day combo.

 

Sample 1 - For Order Date 10 Jan, Products received on Second Business Day that is 13 Jan should count for Products Received on 13 Jan (4) + Products Received on prior Holidays (20 (14 Jan( + 20 (15 Jan) ) = 44

Table 1   Table 2
Order dateOrder Received DateProducts Received Business Day
10-Jan10-Jan1 10-Jan
10-Jan11-Jan20 13-Jan
10-Jan12-Jan20 15-Jan
10-Jan13-Jan4 16-Jan
10-Jan14-Jan3 17-Jan
13-Jan13-Jan9  
13-Jan14-Jan7  
13-Jan15-Jan9  
15-Jan15-Jan8  
15-Jan16-Jan9  
15-Jan17-Jan1  
     
     
     
     
Expected Outcome   
     
Order dateProducts Received Same DayProducts Received Second Business Day
(Including holiday shipments)
Products Received Third Day
(Including holiday shipments)
 
10-Jan1443 
13-Jan9160 
15-Jan891 
1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@curiouspbix0 ,

 

You can add an index column in table2, click query editor-> Transform-> Add Index Column, then create three measures as pattern below and drag Date column and the three measures to a table chart:

Products Received Second Business Day(Including holiday shipments) = 
VAR Current_Date = MAX(Table1[Order date])
VAR Current_Index = CALCULATE(MAX(Table2[Index]), FILTER(Table2, Table2[Business Day] = Current_Date))
VAR Second_Date = CALCULATE(MAX(Table2[Business Day]), FILTER(Table2, Table2[Index] = Current_Index + 1))
RETURN
CALCULATE(SUM(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] > Current_Date && Table1[Order Received Date] <= Second_Date))
Products Received Same Day = 
VAR Current_Order_Date = MAX(Table1[Order date])
VAR Current_Received_Date = CALCULATE(MAX(Table1[Order Received Date]), FILTER(Table1, Table1[Order Received Date] = Current_Order_Date))
VAR Current_Products = CALCULATE(MAX(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] = Current_Received_Date))
RETURN
IF(Current_Order_Date = Current_Received_Date, Current_Products)
Products Received Third Day (Including holiday shipments) = 
VAR Current_Date = MAX(Table1[Order date])
VAR Current_Index = CALCULATE(MAX(Table2[Index]), FILTER(Table2, Table2[Business Day] = Current_Date))
VAR Second_Date = CALCULATE(MAX(Table2[Business Day]), FILTER(Table2, Table2[Index] = Current_Index + 1))
VAR Current_Product = CALCULATE(MAX(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] = Current_Date))
VAR Second_Product = CALCULATE(MAX(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] = Second_Date))
RETURN
Second_Product - Current_Product

Capture.PNG  

 

You may also refer to appendix.

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@curiouspbix0 ,

 

You can add an index column in table2, click query editor-> Transform-> Add Index Column, then create three measures as pattern below and drag Date column and the three measures to a table chart:

Products Received Second Business Day(Including holiday shipments) = 
VAR Current_Date = MAX(Table1[Order date])
VAR Current_Index = CALCULATE(MAX(Table2[Index]), FILTER(Table2, Table2[Business Day] = Current_Date))
VAR Second_Date = CALCULATE(MAX(Table2[Business Day]), FILTER(Table2, Table2[Index] = Current_Index + 1))
RETURN
CALCULATE(SUM(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] > Current_Date && Table1[Order Received Date] <= Second_Date))
Products Received Same Day = 
VAR Current_Order_Date = MAX(Table1[Order date])
VAR Current_Received_Date = CALCULATE(MAX(Table1[Order Received Date]), FILTER(Table1, Table1[Order Received Date] = Current_Order_Date))
VAR Current_Products = CALCULATE(MAX(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] = Current_Received_Date))
RETURN
IF(Current_Order_Date = Current_Received_Date, Current_Products)
Products Received Third Day (Including holiday shipments) = 
VAR Current_Date = MAX(Table1[Order date])
VAR Current_Index = CALCULATE(MAX(Table2[Index]), FILTER(Table2, Table2[Business Day] = Current_Date))
VAR Second_Date = CALCULATE(MAX(Table2[Business Day]), FILTER(Table2, Table2[Index] = Current_Index + 1))
VAR Current_Product = CALCULATE(MAX(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] = Current_Date))
VAR Second_Product = CALCULATE(MAX(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] = Second_Date))
RETURN
Second_Product - Current_Product

Capture.PNG  

 

You may also refer to appendix.

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thanks Jimmy.

That is an awesome way of using a dax function, very impressive.

As an DAX novicer, am trying to still wrap my brains around the formula you have written using variables.

 

Products Received Second Business Day(Including holiday shipments) = 
VAR Current_Date = MAX(Table1[Order date])
VAR Current_Index = CALCULATE(MAX(Table2[Index]), FILTER(Table2, Table2[Business Day] = Current_Date))
VAR Second_Date = CALCULATE(MAX(Table2[Business Day]), FILTER(Table2, Table2[Index] = Current_Index + 1))
RETURN
CALCULATE(SUM(Table1[Products Received]), FILTER(Table1, Table1[Order Received Date] > Current_Date && Table1[Order Received Date] <= Second_Date))

 

If I recreate each variable as a new column the end result does not match up,  could you educate me on what basics am I missing here, as am trying to use this as a foundation to the larger requriement. D.jpg

@curiouspbix0 ,

 

You can't create calculate columns for each parameters because this may achieve the Maximun Date in one column. However, MAX(Table[Date]) in measure only means the current row context, not the Maximun value. I would suggest you to refer to: https://www.sqlbi.com/articles/row-context-and-filter-context-in-dax/

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.