Power Query DAX sortedrows

Hi, I'm trying to filter a query using the current year - 5 (to get everything that's only 5 years old).  I've tried a number of functions but continue to get an error. 
The UI produces the following statement if I type in a date:  = Table.SelectRows(ChangedType, each [IncorporationDate] > #date(2008, 8, 31))
What I'm trying to achieve is : = Table.SelectRows(ChangedType, each [IncorporationDate] > #date(YEAR(TODAY()), 8, 31))
Can anyone help point me to the right solution.
Thanks, Tim.
Thank you for you time folks!

= Table.SelectRows(ChangedType, each [IncorporationDate] > #datetime(Date.Year(DateTime.LocalNow()), 1, 1, 0, 0, 0))
This uses DateTime.LocalNow() to get the current date and which is then parsed through Date.Year to convert it to just the year.   The following numbers you could amend to the month, day and time needed.
Here is a library of formulas if you were not aware
Power Query Formula Library
Regards

Similar Messages

  • Pushing more calcs to Power Query - replacing DAX RANKX

    I have another Power Query calculated column challenge.
    Customer introduced a new requirement. Staff can work multiple shifts in a single business date. They would like a flag if the timesheet entries overlap. Many of their establishments close after midnight, which makes calculations a bit trickier, but there
    is a field for the "business date" of the shift which helps.
    You can imagine source data like this:
    Full Name Date Start Date End Date
    Joe Smith 8/1/2014 8/1/2014 10:00 8/1/2014 18:00
    Joe Smith 8/1/2014 8/1/2014 22:00 8/2/2014 1:00
    Jane Doe 8/1/2014 8/1/2014 15:00 8/1/2014 18:00
    Jane Doe 8/1/2014 8/1/2014 17:00 8/1/2014 17:45
    John Brown 8/1/2014 8/1/2014 19:00 8/2/2014 1:00
    John Brown 8/1/2014 8/1/2014 14:00 8/1/2014 16:00
    John Brown 8/2/2014 8/2/2014 10:00 8/2/2014 18:00
    Mary Black 8/1/2014 8/1/2014 18:00 8/2/2014 1:00
    Mary Black 8/1/2014 8/1/2014 15:00 8/1/2014 21:00
    Bob Walker 8/1/2014 8/1/2014 11:00 8/1/2014 14:00
    Bob Walker 8/1/2014 8/1/2014 17:00 8/1/2014 22:00
    Bob Walker 8/1/2014 8/1/2014 19:00 8/2/2014 1:00
    In this case, Jane Doe, Mary Black, and Bob Walker have overlapping shifts. Joe Smith and John Brown do not.
    I did the calculation in calculated columns in Power Pivot by ranking the start time on the date, ranking the end time on the date, then brute force checking to make sure the start and end dates are in the right order using some intermediate calc columns.
    To do the ranking, I used the DAX RANKX function.
    Now if I want to push this sort of logic back to Power Query. How do I do this? I do not see a ranking function in the formula reference as a starting point for my calculation. 
    Thanks

    Cathy, the following are a couple of rank functions I created as part of a custom stat function "library." Hopefully, they are self-explanatory.
    //RankEqual Function
    (inputValue as any, inputSeries as list, optional orderDescending as nullable logical) as number =>
    let
        SortedSeries = if orderDescending or orderDescending = null then
                                    List.Sort(inputSeries,Order.Descending)
                               else
                                    List.Sort(inputSeries),
        RankEqual = List.PositionOf(SortedSeries,inputValue)+1
    in
        RankEqual
    //RankDense Function
    (inputValue as any, inputSeries as list, optional orderDescending as nullable logical) as number =>
    let
        SortedSeries = if orderDescending or orderDescending = null then
                                     List.Sort(inputSeries,Order.Descending)
                               else
                                     List.Sort(inputSeries),
        DistinctSeries = List.Distinct(SortedSeries),
        RankDense = List.PositionOf(DistinctSeries,inputValue)+1
    in
        RankDense

  • How can I create dynamic file references in Power Query?

    Hi all,
    I'm new at using PowerQuery, and so far I like it. There's one thing I am struggling with though... Once I have set up my PoweQuery connections, I don't find an easy way to change the file to which the query is connecting. I'm using it for a monthyl recurring
    process, and every month the source data to query on woudl be different. The same in format/structure, but just a different dataset.
    Is there a way to make the source setup more dynamic? Can I for example in a parameters sheet enter the name and path of the new source file and update the queries?
    Currently the Advanced editor shows me following file reference:
    let
        Source = Excel.Workbook(File.Contents("Z:\Templates\EMEA\Source Data Tables\EMEA_EW_Source_Data_for_Power_Queries v1.xlsm")),
    Thanks in advance for suggestions

    Yes, this is something that you can do with Power Query. Here's how you can do it:
    Create a table in Excel containing your parameter value. Let's say that it has one column, called ParameterValue, and one row.
    Create a new Power Query query that gets the data from this table. Call the query something like ParameterQuery.
    In your original query you will now be able to reference values from your parameter query by saying something like this:
    Source = Excel.Workbook(File.Contents(ParameterQuery[ParameterValue]{0})),
    HTH,
    Chris
    Check out my MS BI blog I also do
    SSAS, PowerPivot, MDX and DAX consultancy
    and run public SQL Server and BI training courses in the UK

  • Login details in Power Query

    Hi all - 
    How can we get the details of login user dynamically in power query advanced editor.
    Here is the scenario that I'm trying to solve. 
    I have the list of employees and their details extracted from a database and published thru power query. I will share the query with all the employees that I have extracted. Now I want the employee to see his/her specific details only when they login and
    run the query that I shared.
    We can add a filter to our query in the advanced query editor, but the filter value should be  the logged on user. I need to know how can we get the logged on user details in the power query advanced editor.
    Thanks for the help,
    Deva.

    I'm sure you're well aware of the requirement, but can I add my vote for a function that returns the Windows username of the person currently running the query? It would be very useful...
    Chris
    Check out my MS BI blog I also do
    SSAS, PowerPivot, MDX and DAX consultancy
    and run public SQL Server and BI training courses in the UK

  • Aggregating across many-to-many relationship in Power Query?

    Hi, another M question.
    I am trying to push all my DAX calculated column logic back to Power Query and what I couldn't figure out is how to aggregate across my many to many relationship.
    Customer has many companies. He has sales for each company on a bunch of dates. Also, he has timesheets for each company for each date. Customer would like to calculate the labour cost for each company and show them as a ratio of sales in the sales report.
    (eg Kitchen labour cost should be x% of food sales)
    Now I am fine writing all the measures in DAX because I can put them in a table isolated from the Power Query tables. But calculated columns I would ideally push back to Power Query. 
    This is the DAX I constructed to put a calc column in the SalesReport table for the Kitchen labour costs
    =CALCULATE(SUM(Timesheet[Labour Cost]), FILTER(Bridge_CompanyDate, Bridge_CompanyDate[CompanyDateKey]=SalesReports[CompanyDateKey]), FILTER(Timesheet, Timesheet[Category]="Kitchen"))
    Is there a way to do similar types of aggregation in Power Query? I am tired of rewriting these calc columns when I have to reload the thing in the data model :(
    Thanks

    Hi Cathy. You can do this kind of calculation in Power Query, but it's not quite the same as in Power Pivot/DAX.
    If I understand your DAX expression correctly, you're wanting the sum of the [Labour Cost] column from the Timesheet table, for all rows with a [Category] of "Kitchen", where the timesheet date matches the date of the current row in the SalesReport table.
    In M, this would look something like this:
    = Table.AddColumn(Source, "Kitchen Labour Cost", each let expectedDate = [Date] in List.Sum(Table.SelectRows(Timesheet, each [Category] = "Kitchen" and [Date] = expectedDate)[Labour Cost]))
    (Instead of going through the Bridge_CompanyDate table, I'm matching the SalesReport and Timesheet dates directly just to make the example simpler.)
    Let me know if that helps.
    Ehren

  • Can not see new Power Query data sources?

    Hi, 
    New Power Query can connect to three new data sources: Sybase IQ, Exchange, Dynamics CRM Online
    http://office.microsoft.com/en-us/excel-help/whats-new-in-power-bi-ha104149776.aspx
    I just installed the latest Power Query and wanted to connect to CRM Online instance. For some reason I can not see these new data sources, what am I missing?
    Thanks in advance!

    Hmm... I didn't think we had quite released this version yet. It's possible that that website went live before the link to the new download. There should be a blog entry about this on the "Power BI" blog in the very near future.
    At the risk of providing a spoiler :), the CRM Online support is via OData.

  • Multiple Table.AddColumn command in a single Power Query

    I was using this example in another thread for another question and this issue popped up.
    I have this list in sharepoint.
    When I run this Power Query
    let
    Source = SharePoint.Tables("https://server/test"),
    PQtesting = Source{[Name="PQtesting"]}[Content],
    RemovedColumns = Table.RemoveColumns(PQtesting,{"ContentTypeID", "ContentType", "CreatedById", "ModifiedById", "Owshiddenversion", "Version", "Path", "Attachments"}),
    Custom1 = Table.AddColumn(RemovedColumns, "Options 2", each Text.Combine([Options][Value], ", ")),
    Custom2 = Table.AddColumn(RemovedColumns, "Options 1", each Text.Combine([Options][Value], " and "))
    in
    Custom2
    Only column Custom2 shows up in the output, if I remove custom2 then custom1 shows up.  It appears only one custom column shows up at a time as I can swap them and the custom column on the bottom will always show in the output.  I have found examples
    online of others using multiple custom columns.  Is this a limitation of something I'm doing in my code or of sharepoint, or am I doing something wrong?
    Thanks in advance,
    Eric

    I'm a bit embarrassed on how long I have been trying to figure this out.
    Thank you so much for your help.
    Eric

  • Visual studio online - Excel power query usage and samples needed

    Background
    Visual Studio Online does not offer much in the way of reporting, when compared to (onsite) TFS... unless you utilize the REST API functionality.
    The Visual Studio Online REST API is fairly extensive, but not very 'reporting' friendly to applications like Microsoft Excel.
    Question
    Are there any good examples of Microsoft Excel Power Query usage - to acquire and create reports via the Visual Studio Online REST API?  I've searched - but surprisingly haven't found anything of substance.  It is fairly simple to call a VSO REST
    query using Excel Power Query, but not so simple to iterate through the lists within lists, etc... unless you are familiar with 'M language'.

    Hi,
    Thank you for reaching out to us. I am currently researching to gather more information with regards to your request. I shall revert back to you with an update at the earliest. Sincerely appreciate your patience.
    Regards,
    Nithin Rathnakar

  • Connecting Power Query to SharePoint Foundation 2010

    I'm looking to set up PowerQuery in Excel 2013 to link into the various lists on our SharePoint 2010 Foundation server.
    I have established the connection URL.
    The SharePoint Foundation 2010 server is on the same LAN I'm connected to, so I've opted for Windows Authentication.
    These two aspects of the setup appear to be fine: However at the point when Power Query links to the SharePoint server the following error is being returned.
    DataSource.Error: OData: The feed's metadata document appears to be invalid.
    Any ideas?

    Hi,
    We have forum for Power Query discussion and feedback. I will move your post to that forum:
    https://social.technet.microsoft.com/Forums/en-us/home
    The reason why I move your post is to get you the most qualified pool of respondents, and other partners who read the forums
    regularly can either share their knowledge or learn from your interaction with us.
    Thank you for your understanding.

  • Power Query/Data Management Gateway data refresh not working

    Pretty new to o365/Power BI, but here's what I've got going on (hopefully someone can help me out):
    I created a data management gateway and data source.  The data source says it's online in the PowerBI admin center, and it seems to be working correctly.  I can open Excel 2013 on my desktop (logging in as my trial o365 account which has Power
    BI associated with it) and connect to the data source via Power Query using the oData option.  I make sure to import the data into the model, and then open up the PowerPivot window and create a simple pivot table using the data in the model.
    that all works just great.  The problem comes when I upload the workbook and try to update it.  I've tried a few different ways.
    1. When I try to manually refresh the workbook by opening it in my o365 site and going to data-->refresh I get the following error:
          An error occurred while working on the Data Model in the workbook. Please try again.
          We were unable to refresh one or more data connections in this workbook.
          The following connections failed to refresh:
          Connection: Power Query - dbo_DimProductCategory
          Error: Out of line object 'DataSource', referring to ID(s) 'a75593f3-c34d-4f83-9458-49aa2cece164', has been specified but has not been used.
          The following system error occurred: Class not registered
          The provider 'Microsoft.Mashup.OleDb.1' is not registered.
          Power Query - dbo_DimProductCategory
    2. When I go into Power BI and go to "Schedule Data Refresh" for the workbook, I get the following error:
          Sorry, the data connections in this report aren’t supported for Scheduled Refresh.
          Technical Details â–¼
          Correlation ID: B3CE4B10-2137-E593-6FCF-189B73465190
          Date and Time: 03/31/2014 06:20:39 PM (UTC)
    Any help would be greatly appreciated.  If you need additional information, I'd be happy to provide it.

    Hey Guy,
    Thanks for the reply.
    The "data source type" of the data source in Power BI is "SQL Server" (there was only that and Oracle available to select from)
    The "data source type" that Power Query is using in Excel is "From oData Feed"....which is using the Power BI data source....which is using the data management gateway.
    A few follow up questions if you have a second
    1. Do you know when PowerQuery data refresh will be supported? (just a general idea....weeks, months, next year?)
    2. Is there any other way to connect to (and be able to refresh) PowerBI data sources referencing "on prem" data via the data management gateway?  I tried using the oData feed URL in non-PowerQuery areas of excel (excel data tab, PowerPivot directly)
    but it didn't work.  If there's some other way to connect to and refresh on prem data, i'm all ears :D 
    Really appreciate your help, thanks for taking the time.

  • POWER QUERY Get External Data From File From Folder (Excel 2013)

    Hi,
    Beginner's question :
    What could be the use of the query on a folder : we just get a list of files with their path. What can we do with that?
    Thanks

    Hi,
    Do you want to combine data from multiple Excel Files in the same folder path into one table? If I understand correct, we can add a custom column to import the data.
    After we getting a list of files with their path, the Query Editor window will activate to show you a table containing a record for each file in the chosen directory. These will provide our function with the needed FilePath and FileName parameters. 
    Function sample: File name([Folder path],[Field name]
    For more detailed steps, please see the article:
    http://datapigtechnologies.com/blog/index.php/using-power-query-to-combine-data-from-multiple-excel-files-into-one-table/
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Can I use Power Query to Import a table from Excel sheet range which starts not from the top row?

    Hi,
    Being an experienced Excel user before Power BI, I am just starting to explore the M and Power Query capabilities, and need help already (ain't easy to google this use case somehow):
    I need to import the table which sits in the Excel file with header row in the row 17 of Excel sheet, with some metadata header in the preceding rows of the columns A and B.
    01: Report name, Quick Report
    02: Report Date, 1/1/2014
    17: Employee Name, Manager, etc...
    18: John Doe, Matt Beaver, etc.
    Both (a) direct attempt to load as Excel file and (b) the indirect way through [From Folder] and formula in custom column -- both lead to the same error: "[DataFormat.Error] External table is not in the expected format."
    Specifically, I tried to use the [Power Query -> From File -> From Folder] functionality, select an Excel file and add a custom column to access the binary content: [Add Custom Column] with formula "=Excel.Workbook([Content])".
    It looks like Power Query expects a rectangular range with headers full-width followed by a contiguous table range to import anything, and refuses to load if that is not the case...
    QUESTION: Is there any way to load whatever-formatted data from Excel first, and then manipulate the overall imported range (like referring to rows starting from 17th using "Table.SelectRows" etc.) to read the actual data? Reading and using
    the metadata from header would be a bonus, but that comes second... The main issue is to get something from a non-regular Excel file to later work with using M formulae ...
    Thanks!
    SAM

    Finally found the answer to this one in ():
    You Cannot Open a Password-Protected Workbook
     If the Excel workbook is protected by a password, you
      cannot open it for data access, even by supplying the correct password with
      your connection settings, unless the workbook file is already open in the
      Microsoft Excel application. If you try, you receive the following error
      message:
    Could not decrypt file.
    ANSWER: So, will have either weave in the work with temporary unprotected files or requires opening them before updating the data source (although this almost defeats the purpose of automation...)
    ANSWER to ORIGINAL QUESTION: password was preventing Power Query from reading the Excel file. For solution see above.
    Thanks anyway for participation and inspiration, Imke!

  • Data loaded to Power Pivot via Power Query is not yet supported in SSAS Tabular Cube

    Hello, I'm trying to create a SSAS Tabular cube from a data loaded to Power Pivot via Power Query (SAP BOBJ connector) but looks like is not yet supported.
    Any one tried this before? any workaround that make sense?
    The final goal is pull data from SAP BW, BO Universe (using PowerQuery) and be able to create a SSAS Tabular cube.
    Thanks in advance
    Sebastian

    Sebastian, 
    Depending on the size of the data from Analysis Services, one work around could be to import the data into into Excel and then make an Excel table and then use the Excel table as a data source. 
    Reeves
    Denver, CO

  • Running a SQL Stored Procedure from Power Query with Dynamic Parameters

    Hi,
    I want to execute a stored procedure from Power Query with dynamic parameters.
    In normal process, query will look like below in Power Query. Here the value 'Dileep' is passed as a parameter value to SP.
        Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData 'Dileep'"]
    Now I want to pass the value dynamically taking from excel sheet. I can get the required excel cell value in a variable but unable to pass it to query.
        Name_Parameter = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
        Name_Value = Name_Parameter{0}[Value],
    I have tried like below but it is not working.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData Name_Value"]
    Can anyone please help me with this issue.
    Thanks
    Dileep

    Hi,
    I got it. Below is the correct syntax.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData '" & Name_Value & "'"]
    Thanks
    Dileep

  • How to use power query with sitecatalyst

    Hello,
    I need to use power query to import a table from sitecatalyst. Doing some tests I found that If remove the session from the url that has the report parameters, the app will redirect me to the login page, after entering the company, username and password
    it will load the report page with the data according to my filters.
    When I add the report url on the From Web option, excel does not allow me to add credentials. If I add the login+redirect url it allows me to add user/password but does not load the tables that appear on a regular browser.
    Is it possible to consume sitecatalyst without using Report Builder? If not, how you access the security info after you added the url.
    Thanks.

    To the best of my ability to tell, the right way to use this product from within Power Query would be to use its API. Unfortunately, we don't currently support either of the methods needed to be able to authenticate with the service (OAuth 2.0 and a relatively-custom
    digest-based method). Adding a mechanism to allow use of arbitrary OAuth-protected resources is a fairly high priority for us, and I hope we'll be able to deliver something before mid-2015.
    Scraping the website is very hard to do well -- both from an authentication and from a data discovery perspective.

Maybe you are looking for