Power Automate
SECTION 05 · LAB 5.1

Improve the
purchase notification.

Use expressions to clean text, format a timestamp, calculate a fee, and handle an empty business reason.

Guided practice · Text, dates, numbers & empty values

Read a value. Transform a value.

Dynamic content gives you a value from an earlier step. An expression can transform that value or calculate a new one. Use fx to enter the expression into a field.

How to use every expression box below

Select Copy expression. Click the destination field in the email action, place the cursor where the value belongs, select fx, paste the code, and select Add or Update. Enter code in the expression editor, not as ordinary text in the email. Do not add an equals sign or an @ prefix.

The fx button opens the expression editor. This earlier screenshot illustrates the same entry method; use the complete code for each step below.
The fx button opens the expression editor. This earlier screenshot illustrates the same entry method; use the complete code for each step below. · Select the image to enlarge.

Make these changes inside the email action in Apply to each. Here, item() refers to the current Excel row. Save and test after each improvement to see its effect.

STEP 01

Copy the loop-only flow

  1. Find Purchases from Excel from Lab 4.1—the version that sends an email for every row.
  2. Use Save As to create a copy named Purchase Improve notification, matching the screenshot.
  3. Open the copy for editing. Keep the Excel action, Apply to each, and email action.
  4. After saving your changes, enable the copied flow before testing.

Use the loop-only flow so both remaining rows generate emails. The greater-than-1000 condition from Lab 4.2 is not part of this lab.

Create a separate flow for the notification improvements.
Create a separate flow for the notification improvements. · Select the image to enlarge.
STEP 02

Keep two rows and read the file again

  1. Open the OneDrive copy of PurchaseRequests.xlsx—the file selected in your Excel action.
  2. Delete the three table data rows for Keyboard, Meeting room screen, and Headset. Keep Monitor and Office chairs.
  3. Keep the table headers and the PurchaseRequests table name. Delete the rows rather than only clearing their cells.
  4. Wait for the workbook to finish saving, then run the flow.
  5. Expand Apply to each in the run result. It should show 1 of 2, rather than 1 of 5.
The saved table now contains only Monitor and Office chairs.
The saved table now contains only Monitor and Office chairs. · Select the image to enlarge.
Every run visits the workbook again

When this flow runs, List rows present in a table reads the saved file in OneDrive again. It does not keep the five rows from an earlier run. The loop processes the rows returned by that read, so the next run now has two iterations.

Editing the file does not start this manually triggered flow. Save the file, then run the flow again. If you edit it after the Excel action has already read the rows, those edits belong to a later run.

Two rows in the current file produce two iterations in this run.
Two rows in the current file produce two iterations in this run. · Select the image to enlarge.
STEP 03

Clean the item name and make the subject uppercase

Open the email action and replace the Item name token in Subject with this expression.

fx · Uppercase subject
toUpper(trim(item()?['Item name']))

  1. item()?['Item name'] gets the current row’s item name.
  2. trim(...) removes spaces from the beginning and end.
  3. toUpper(...) converts the result to uppercase.

The functions work from the inside out. For example, Office chairs becomes OFFICE CHAIRS. The sample names already have no outside spaces, so the visible change is uppercase. Keep the body’s Item name token unchanged to compare the two.

Save, run, and check the subjects of the two new emails.

Subjects are uppercase while the body retains the original item name.
Subjects are uppercase while the body retains the original item name. · Select the image to enlarge.
STEP 04

Add a readable run timestamp

At the bottom of the email body, type created on , then insert this expression using fx.

fx · Formatted UTC timestamp
formatDateTime(utcNow(), 'dd/MM/yyyy HH:mm')

utcNow() supplies the current UTC time when evaluated. formatDateTime() displays it using our chosen pattern: day/month/year and a 24-hour time. MM means month; mm means minutes.

Formatting is not time-zone conversion

This value is UTC. In the screenshot the body shows 11:49 while Outlook displays 2:49 PM in Qatar. The expression formats the timestamp; it does not add Qatar’s three-hour offset. It also represents when the expression is evaluated, not when the Excel request was created.

Save and run again. Check the new timestamp in the latest email.

The body includes a formatted UTC timestamp; Outlook’s displayed local time differs.
The body includes a formatted UTC timestamp; Outlook’s displayed local time differs. · Select the image to enlarge.
STEP 05

Calculate a 5% fee

Add a new line after the business reason, type 5% fee: , and insert this expression.

fx · Five percent fee
mul(float(item()?['Estimated cost']), 0.05)

float() converts the Excel cost to a number. mul(..., 0.05) multiplies it by 5%. This is the fee amount, not the total including the fee.

ItemEstimated cost5% fee
Monitor85042.5
Office chairs150075

Save, run, and compare the calculated fee with the current row’s cost. The sample is a training fee calculation.

For Office chairs, a cost of 1500 produces a fee of 75.
For Office chairs, a cost of 1500 produces a fee of 75. · Select the image to enlarge.
STEP 06

Provide a fallback when the reason is blank

  1. Open the same workbook in OneDrive.
  2. Clear only the Business reason cell for Office chairs. Keep the row, item name, and cost.
  3. Wait for the workbook to finish saving.
  4. In the email action, replace the Business reason token with the agreed expression below.
Office chairs still exists, but its Business reason cell is now empty.
Office chairs still exists, but its Business reason cell is now empty. · Select the image to enlarge.
fx · Fallback for an empty business reason
if(empty(item()?['Business reason']), 'No reason Given', item()?['Business reason'])

empty(...) checks whether the value is empty. if() returns No reason Given when that check is true; otherwise it returns the row’s original business reason.

This expression returns a value inside an email field. It does not add a separate Condition control or a new branch. A cell containing only spaces is not empty, so clear the cell completely for this test.

Save and run again. Monitor should retain Report preparation, while Office chairs should show No reason Given. Both rows still produce emails.

The latest file values are used on the next run

You did not change the flow’s data-source selection. The next execution reads the same workbook again and sees the newly empty cell. Previous emails remain unchanged; the next emails reflect the current saved data.

The new Office chairs email uses No reason Given while retaining its cost and calculated fee.
The new Office chairs email uses No reason Given while retaining its cost and calculated fee. · Select the image to enlarge.
SUCCESS CHECK

Same flow, clearer information.

  • Two current table rows produce two emails per run.
  • The subject is trimmed and uppercase.
  • The body contains a readable UTC timestamp and the calculated 5% fee.
  • A blank business reason produces No reason Given.
  • You can explain that each run reads the saved OneDrive workbook again.

If something does not work

Old rows
Confirm you edited the OneDrive file selected in List rows, not the original download. Wait for saving to finish and start a new run.
Five iterations
Delete the unwanted table rows, not just their contents. Check the table’s current extent.
Code in email
Insert the code through fx rather than typing it as body text. It should appear as an expression token in the designer.
Only one email
Check you copied the loop-only flow, with no cost condition around the email.