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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Gerald23
Helper I
Helper I

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=2HkBbqxBzF0

 

He describes 2 options the first one works but he explains that the second is better performance wise. So I followed the second one and it gives me the code below which works great in the Dax Studio but when I move the code to the Power BI Desktop file it doesnt.

 

So how should I change this code so that it works in a new calculated column in the Power bi Desktop?

 

 

DEFINE COLUMN 'Date'[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
	COLUMN 'Sales'[WDN+5] =
		VAR CurrentWDN = RELATED( 'Date'[WDN] )
		VAR CurrentPlus5 = CurrentWDN + 5
		VAR Result =
			LOOKUPVALUE(
			'Date'[Date],
			'Date'[WDN], CurrentPlus5,
			'Date'[Working Day], TRUE
			)
		RETURN
			Result
EVALUATE
	ALL ( 'Sales'[Period.Date Value], 'Sales'[WDN+5])
ORDER BY 'Sales'[Period.Date Value]

 

 

1 ACCEPTED SOLUTION
Gerald23
Helper I
Helper I

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.

View solution in original post

2 REPLIES 2
Gerald23
Helper I
Helper I

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.

daXtreme
Solution Sage
Solution Sage

This is a QUERY, not something you can put in PBI just like that. If you want to create a column in a table, then you should extract the pieces that can be used in a calculated column. Certainly, you CANNOT DEFINE anything in a calc column.

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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