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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
aallman
Helper I
Helper I

Return date value from date table that is X number of FILTERED dates away

Hello! I need some help with a DAX formula please!

 

I need to return a Calculated Ship Date column. This is based on Order Date + X number of working days. My date table has each date indicated as a working day Y/N (actually it is 1 or 0). How can I use the date table, start with my Order Date and move up X rows where WorkingDay = 1 and return that date?

 

For example - I need to add a column to my data table called "Calculated Ship Date" and it should return 1/9/24.

My Data Table

OrderDateLocationWorking DaysCalculated Ship Date
1/4/24USA31/9/24

 

DateTable

DateUSA WorkingDayAsia WorkingDay
1/4/2411
1/5/2411
1/6/2401
1/7/2400
1/8/2410
1/9/2411
1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @aallman,

 

You can try this one:

 

barritown_0-1706352651394.png

DAX code in plain text:

Calculated Shipping Date = 
VAR currentDate = [OrderDate]
VAR currentLoc = [Location]
VAR workDay = [Working Days]
RETURN SWITCH ( TRUE(),
    currentLoc = "USA",
    VAR _tbl = FILTER ( ref, [USA WorkingDay] = 1 && [Date] > currentDate )
    VAR _tbl2 = ADDCOLUMNS ( _tbl, "ID", RANKX ( _tbl, [Date], , ASC ) )
    RETURN MINX ( FILTER ( _tbl2, [ID] = workDay ), [Date] ),
    currentLoc = "Asia",
    VAR _tbl = FILTER ( ref, [Asia WorkingDay] = 1 && [Date] > currentDate )
    VAR _tbl2 = ADDCOLUMNS ( _tbl, "ID", RANKX ( _tbl, [Date], , ASC ) )
    RETURN MINX ( FILTER ( _tbl2, [ID] = workDay ), [Date] )
    )

Please also find the attached PBIX file.

 

If you can change your DateTable (Date - Location - Working Day Flag), the calculation column can be simplified.

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

View solution in original post

1 REPLY 1
barritown
Super User
Super User

Hi @aallman,

 

You can try this one:

 

barritown_0-1706352651394.png

DAX code in plain text:

Calculated Shipping Date = 
VAR currentDate = [OrderDate]
VAR currentLoc = [Location]
VAR workDay = [Working Days]
RETURN SWITCH ( TRUE(),
    currentLoc = "USA",
    VAR _tbl = FILTER ( ref, [USA WorkingDay] = 1 && [Date] > currentDate )
    VAR _tbl2 = ADDCOLUMNS ( _tbl, "ID", RANKX ( _tbl, [Date], , ASC ) )
    RETURN MINX ( FILTER ( _tbl2, [ID] = workDay ), [Date] ),
    currentLoc = "Asia",
    VAR _tbl = FILTER ( ref, [Asia WorkingDay] = 1 && [Date] > currentDate )
    VAR _tbl2 = ADDCOLUMNS ( _tbl, "ID", RANKX ( _tbl, [Date], , ASC ) )
    RETURN MINX ( FILTER ( _tbl2, [ID] = workDay ), [Date] )
    )

Please also find the attached PBIX file.

 

If you can change your DateTable (Date - Location - Working Day Flag), the calculation column can be simplified.

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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