How to translate Excel Functions to Power Query M for IF and XLOOKUP functions?

Joel Taylor 71 Reputation points
2020-09-30T09:20:04.867+00:00

Hi,

I am new to Power Query Editor (is this abbreviated PQE?) and have been using it to automate the process of editing data from a *.csv.

I have been trying to add a custom column to PQE. However, in my naivety, I was unaware that Excel functions are different to PQE functions. I created the code in a test page of Excel and attempted to copy it over when it wouldn't work. I have/had been attempting to translate the functions to the equivalent M code but was unable to do so. If anyone can help inform me of the equivalent functions in M or help translate the whole code, I would appreciate it.

In PQE, I have 20 columns. Ten of these begin with "Period.", ten begin with "Attend_Status." such that all columns (from left to right) would read: Period.1, Period.2, ..., Period.10, Attend_Status.1, Attend_Status.2, ..., Attend_Status.10.

The code, ignoring references to the table, is:
=IF(XLOOKUP("Home Class",[PERIOD.1]:[PERIOD.10],[ATTEND_STATUS.1]:[ATTEND_STATUS.10],"",0,-1)="Absent",IF(COUNTIF([ATTEND_STATUS.1]:[ATTEND_STATUS.10],"Late Signed In")>0,"","!!!"),IF(XLOOKUP("EVENT",[PERIOD.1]:[PERIOD.10],[ATTEND_STATUS.1]:[ATTEND_STATUS.10],"",0,-1)="Absent",IF(COUNTIF([ATTEND_STATUS.1]:[ATTEND_STATUS.10],"Late Signed In")>0,"","!!!"),""))

As you can see, in the code are four nested IF functions, two similar XLOOKUP functions and two duplicate COUNTIF functions. The purpose of the code is to filter (if that is the correct nomecleture) the rows of data and inform me if a given row matches the given conditions - that is, the student is absent in the Home Class or Event and did not sign in later. Specifically, the formula reads:

IF the equivalently positioned value for "Home Class" (using XLOOKUP) is "Absent",
then IF (2nd nested IF) the text "Late Signed In" is present in the range (COUNTIF>0), then BLANK ("") is displayed, else display "!!!",
else IF (3rd IF in last value_if_false) the value in the equivalent position of "Event" (similar XLOOKUP) is "Absent",
then IF (4th IF) the text "Late Signed In" is present (same as above), then BLANK ("") is displayed, else display "!!!".

I tried to create the proper function using M with IF (then, else) and List.PositionOf, but I couldn't quite work it out and I wasn't sure if that was the best method/function to use anyway.

If anyone is able to point me in the correct direction or translate my code, I would greatly appreciate it.

Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,715 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Leon Laude 85,786 Reputation points
    2020-09-30T09:48:08.163+00:00

    Hi @Joel Taylor ,

    They are also actively answering in the dedicated Power Query forum over here:
    https://social.technet.microsoft.com/Forums/en-US/home?forum=powerquery

    ----------

    (If the reply was helpful please don't forget to upvote or accept as answer, thank you)

    Best regards,
    Leon

    1 person found this answer helpful.
    0 comments No comments

  2. Emily Hua-MSFT 27,641 Reputation points
    2020-10-01T01:18:17.673+00:00

    @Joel Taylor ,

    We are mainly responsible for general issues of Office desktop applications, but your question focus more on code in Power Query, to help you better, it's recommended to post this questions in the forums below.

    Power Query

    Microsoft Power BI Community

    Thanks for your understanding.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. Joel Taylor 71 Reputation points
    2020-10-05T04:46:01.11+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.