Forum Discussion

Gerald23's avatar
Gerald23
Icon for Helper I rankHelper I
4 years ago
Solved

DAX Code not working in PBI Desktop

Hi Everyone,   I would like to add 5 working days to a date I already have in my Sales table. To achieve this i have followed the steps described in this video: https://www.youtube.com/watch?v=2HkB...
  • Gerald23's avatar
    4 years ago

    So I was able to solve this by splitting the code so that it would make two new calculated columns instead of just one.

     

    First i created a column called WDN using the code below 

    WDN = 
    	VAR WorkingDates = 
    		CALCULATETABLE(
    			Values ( 'Date'[Date]),
    			REMOVEFILTERS ( 'Date'),
    			'Date'[Working Day] = TRUE
    			)
    	VAR Result = 
    		RANKX ( WorkingDates, 'Date'[Date], , ASC ) - NOT ('Date'[Working Day])
    	RETURN
    		Result

     

    Then i added another calculated column called WDN+5 using this code

    WDN+5 = 
    		VAR CurrentWDN =  'Date'[WDN]
    		VAR CurrentPlus5 = CurrentWDN + 5
    		VAR Result =
    			LOOKUPVALUE(
    			'Date'[Date],
    			'Date'[WDN], CurrentPlus5,
    			'Date'[Working Day], TRUE
    			)
    		RETURN
    			Result

     

    Now I can use this field in filtering to get the results that are needed for my report.