Forum Discussion

wi11iamr's avatar
wi11iamr
Icon for Advocate II rankAdvocate II
9 years ago
Solved

Select value from table as input to PowerQuery DateKey function

Hi there,

 

I have a Date Function which creates a DateKey, and this function takes a StartDate and EndDate as parameter.

I've traditionally used the function with a List.Min and List.Max function to find my Start and End dates, as follows:

 

 

= fnDateDim(Date.From(List.Min(AssetRegister[dDatecreated])),
                      Date.From(List.Max(AssetRegister[dDatecreated]))
                     )

Looking for the Min and Max values has however become unnecessarily laborious as the entire table is loaded before the Min and Max dates are identified, and for large tables, this is a waste.

 

I've since created a summarised dateRange table with Start and End dates for various attributes Date Types:

DateType                 StartDate        EndDate

InventoryDate2016/07/062017/09/02
InstallationDate1970/01/012020/07/21
ReportDate2017/02/282017/09/05
AuditDate2017/09/052017/09/11

 

 

The trouble I'm having is in trying to use the respective StartDate & EndDate in my DateKey function, as depending on how I use the Table.SelectRows and Table.SelectColumns functions, I get various errors.

 

The below code:

 

= fnDateDim(
	Table.Column(
		Table.SelectRows(dimDateRanges,			
			each [Datetype] = "InstallationDate"), 
		"StartDate"),
Date.From("2017/06/30"), 
"en-us")

Gives the error:

"cannot convert a value of type List to type Date"

 

and then when I try to wrap it in Date.From function:

= fnDateDim(Date.From(
	Table.Column(
		Table.SelectRows(dimDateRanges,			
			each [Datetype] = "InstallationDate"), 
		"StartDate")),
Date.From("2017/06/30"), 
"en-us")

I get the error:

"couldn't convert to Date."

 

Assuming that my Table.SelectRows and Table.Column functions have managed to correctly return the single value of the InstallationDate's StartDate that I am looking for, then I suspect my issue lies in not understanding the format in which a value from a Column is returned.

 

Any pointers welcome!

 

2 Replies