• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Trouble with IF - Token Literal expected error|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Trouble with IF - Token Literal expected error|Power Query|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryTrouble with IF - Token Literal exp…
sp_PrintTopic sp_TopicIcon
Trouble with IF - Token Literal expected error
Avatar
Ryan Kenny
Member
Members
Level 0
Forum Posts: 12
Member Since:
November 2, 2021
sp_UserOfflineSmall Offline
1
April 3, 2023 - 11:50 pm
sp_Permalink sp_Print

Hi all,

This seems like a simple one that I can't quite crack - I'm almost certainly missing something basic, but for the life of me I can't see it, so would appreciate some extra eyes!

I'm trying to add some error handling to this function I'm working on - it works fine in most cases. But some of the values I need to run it against will return an empty table in the middle of the function, and if that happens the subsequent steps give an error.

To deal with that, I thought I could use the branching logic described here: https://community.powerbi.com/.....ba-p/39998

Here is the relevant section of the code:

data = #"API call"[data],

logs = data[logs],

#"Converted to Table" = Table.FromList(logs, Splitter.SplitByNothing(), null, null, ExtraValues.Errror),

//Code to run if the table is not empty

#Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"message", "logged_at", "user"}, {"message", "logged_at", "user"}),

#"Add Date" = Table.AddColumn(#"Expanded Column1", "Date", each DateTime.FromText([logged_at], [Formate = "HH:mm d MMM yyyy"])),

//Test if table is empty

result = if Table.IsEmpty(#"Converted to Table") = true then null else #"Reorder Columns"

in

result

This throws a "Token Literal expected" error, and the "Show error" link in the advanced editor points to that final if statement as the source of the problem.

My understanding is that that error means that a value or function should come after the if, but Table.IsEmpty is a function! What am I missing here?

Any help much appreciated!

Ryan

sp_AnswersTopicSeeAnswer See Answer
Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 648
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
April 4, 2023 - 12:51 am
sp_Permalink sp_Print

The syntax you posted is fine - where is the debugger showing the error point?

sp_AnswersTopicAnswer
Answers Post
Avatar
Ryan Kenny
Member
Members
Level 0
Forum Posts: 12
Member Since:
November 2, 2021
sp_UserOfflineSmall Offline
3
April 4, 2023 - 2:12 am
sp_Permalink sp_Print

That's what I though! By "debugger" do you mean the "Show error" tool in the Advanced Editor? When I clicked that it highlighted the "if" in the if statement at the end

Strangely, I had a duplicate version of the query that was working fine, so I copy-pasted one line at a time from it into the broken version, and now it runs. I'm sure there must have been some difference between the two (I kept the duplicate as a fallback because I was trying to make some changes to the version that broke) but I couldn't spot a single one as I replaced each line.

Nevertheless, it worked and the error is gone so  \_(ツ)_/

 

Thanks for your help and sorry to waste your time!

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 648
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
4
April 4, 2023 - 2:39 am
sp_Permalink sp_Print

No problem - must have been gremlins. 😉

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Alain Balken
Guest(s) 12
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.