+ Reply to Thread
Results 1 to 12 of 12

Improve PQ M code

  1. #1
    Registered User
    Join Date
    05-13-2023
    Location
    German
    MS-Off Ver
    Microsoft 365
    Posts
    27

    Improve PQ M code

    Hello
    I need your professional aid in turn.
    Who can tell me how I can improve the following M code if this is possible?
    Thank you in advance for the help.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Ivan-; 11-19-2023 at 08:04 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Improve PQ M code

    Improve in what way? What is wrong with it?

    Please Login or Register  to view this content.
    For non-German speakers, this means 'and so on up to 200'.

    There are instructions at the top of the page explaining how to attach your sample workbook (yellow banner: HOW TO ATTACH YOUR SAMPLE WORKBOOK). Screenshots are of little practical use as we cannot manipulate them.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    05-13-2023
    Location
    German
    MS-Off Ver
    Microsoft 365
    Posts
    27

    Re: Improve PQ M code

    Hello
    Thank you for your quick reply.
    My M code works great, there are no fel reports.
    I thought there would be a way to improve this code or to show off.
    Somehow reduce all the additional columns through split, which I can't do.
    Would this be possible if so how?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Improve PQ M code

    See post #2 and attach an annotated workbook.

  5. #5
    Registered User
    Join Date
    05-13-2023
    Location
    German
    MS-Off Ver
    Microsoft 365
    Posts
    27

    Re: Improve PQ M code

    Example file is now added

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Improve PQ M code

    I think there will be a much easier way, but please explain the objective - I don't get the logic of the results you're aiming for.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Improve PQ M code

    Does this formula do what you want?

    =SEQUENCE(200,,Tabelle2[@Datum]+Tabelle2[@Uhrzeit],29.5)

    =SEQUENZ(200;;Tabelle2[@Datum]+Tabelle2[@Uhrzeit];29,5)
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-13-2023
    Location
    German
    MS-Off Ver
    Microsoft 365
    Posts
    27

    Re: Improve PQ M code

    Hello
    Thank you for your formula.
    Your formula provides the desired end result, but unfortunately I would like to implement this with PQ because it should also be partially running on older versions.

  9. #9
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Improve PQ M code

    Not sure I fully understand I made this query that will create a list of 200 values with 29 days and 12 hrs in between

    Please Login or Register  to view this content.
    i'm sure this can be incorporated into your actual sheet made to fit. but this code the first line creates the 200 values in a split second. I used "hardcoded" start time because that is easiest
    Last edited by Roel Jongman; 11-19-2023 at 02:41 PM.

  10. #10
    Registered User
    Join Date
    05-13-2023
    Location
    German
    MS-Off Ver
    Microsoft 365
    Posts
    27

    Re: Improve PQ M code

    Hello
    Thanks too for the help.
    Unfortunately, the date is hard -corded in the code, this is not desired.
    The date must be controllable via the table and does not change the M code every time.

  11. #11
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Improve PQ M code

    Well let's try this code then

    i could not get the code to work before due to some naming issues that caused confusion with me..
    so I changed the query "Tabelle2" to "qryTabelle2" to avoid confusion between what is the actual table in worksheet "Tabelle1" and the qeury in which you merged date and time column.
    also changed the columnname from +29 Days to "29 Days" as that +-sing gave issues in the reference

    Please Login or Register  to view this content.
    Only change is in the 29agelist line replaced the hardcoded date/time into a reference of the first datarow of column 29 days in the query qryTabelle2
    which is this part
    qryTabelle2{0}[29 Days]

    also see attached file.
    be aware that Abfrage is now broken because of the name change of the column +29 days
    Attached Files Attached Files
    Last edited by Roel Jongman; 11-19-2023 at 04:00 PM.

  12. #12
    Registered User
    Join Date
    05-13-2023
    Location
    German
    MS-Off Ver
    Microsoft 365
    Posts
    27

    Re: Improve PQ M code

    Hello
    Many love for the PQ solution.
    Unfortunately, due to time constraints, I cannot test the whole thing in the original file.
    If it doesn't work, I'll get in touch again.

    I thank all helpers again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Improve Code
    By jynxy in forum Excel General
    Replies: 2
    Last Post: 09-15-2023, 10:07 AM
  2. Can someone help me Improve my code, please?
    By Energy48 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2023, 05:56 PM
  3. Improve the code
    By yeti330060 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-10-2022, 01:53 AM
  4. How to improve my code ?
    By ozstrik3r69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2017, 08:51 AM
  5. Does this code needs improvement?
    By amartinez988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2016, 09:21 AM
  6. Improve my code: If, or, then
    By Alex532 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-01-2013, 07:19 PM
  7. [SOLVED] To improve Efficiency of code, code running too long
    By andywsw in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2012, 05:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1