Saturday, December 5, 2026

My AI Learning Curve: From Folk Tale to YouTube Video with Google Flow

 

Introduction

In my previous article, I shared my experience creating my first AI-assisted YouTube video and the lessons I learned along the way. That project sparked a new curiosity: could I use AI tools to create an animated folk tale from start to finish?

Many online videos make AI-powered content creation appear straightforward. The promise is appealing. Provide a story idea, generate some visuals, add a voiceover, and publish a video. As someone interested in both storytelling and technology, I wanted to see how much of that promise reflected reality.

This project became the next step in my AI learning journey. Using Google Flow and other supporting tools, I set out to transform a simple folk tale into a complete YouTube video.

What followed was a valuable learning experience that took considerably more time and effort than I originally expected.



AI learning journey using Google Flow to create a folk tale YouTube video, illustrated by a wooden bridge crossing a stream in a countryside landscape.
A small wooden bridge over a stream representing an AI-assisted video creation project

Why I Chose This Story

For this project, I selected the classic folk tale of The Two Goats and the Narrow Bridge.

The story is simple, memorable, and carries a timeless lesson. Two goats approach a narrow bridge from opposite directions. Neither wants to give way, and their stubbornness leads to consequences. The story teaches the value of cooperation, patience, and compromise.

Its simplicity made it an ideal choice for my first AI-generated folk tale project.


What I Expected Before Starting

Before beginning the project, I assumed AI would handle a large portion of the work.

My expectations were:

  • AI would generate most of the content.
  • Image creation would be straightforward.
  • Voice generation would require minimal effort.
  • Turning images into usable animations would be quick and straightforward.
  • The entire project could be completed within a few hours.

In short, I expected AI to do most of the heavy lifting while I reviewed and assembled the final result.

Reality turned out to be quite different.


Developing the Story

The project began with a simple idea and a rough outline.

While AI helped expand the story, the final narrative did not emerge from a single prompt. The process involved refining scenes, improving the flow of events, strengthening the lesson, and ensuring the story remained engaging throughout.

The more guidance I provided, the better the results became.

One of the first lessons I learned was that AI performs best when it works with clear direction rather than without supervision.


Creating the Narration

Once the story structure was complete, I moved on to narration.

I initially expected this stage to be straightforward. However, creating a narration that felt natural required much more than simply converting text into speech.

Adjustments were needed to pacing, wording, emphasis, and scene transitions. Small changes often made a noticeable difference to the quality of the final output.

This stage reinforced an important lesson:

Good AI-generated content still benefits from human refinement.


Generating the Images

Image generation was one of the most interesting parts of the project.

Creating a single image was relatively easy.

Creating a collection of images that looked as though they belonged to the same story was much harder.

Some of the challenges included:

  • Maintaining character consistency.
  • Keeping colours and styles uniform.
  • Ensuring scenes matched previous scenes.
  • Correcting unexpected visual variations.

A significant amount of time was spent refining prompts and reviewing results.

What initially appeared to be a quick task became one of the most iterative parts of the workflow.


Learning Google Flow

A major objective of this project was gaining hands-on experience with Google Flow.

As I worked through the story, I learned more about:

  • Scene generation.
  • Prompt refinement.
  • Reference image usage.
  • Animation creation.
  • Workflow management.

The learning process involved experimentation, trial and error, and multiple revisions before reaching a satisfactory outcome. As I became more familiar with the platform, I developed a better understanding of how prompt wording, reference images, and scene setup influenced the final results. Each iteration helped me improve both the quality of the content and my understanding of the workflow.

By the end of the project, I had gained a much better understanding of both the capabilities and limitations of Google Flow and how it could fit into a wider AI-assisted content creation workflow.

Voice Generation and Licensing

Another area that required more attention than expected was voice generation and licensing.

In addition to selecting suitable voices, I found myself researching:

  • Commercial usage rights.
  • Licensing terms.
  • Monetisation considerations.
  • Subscription options.

Many tutorials focus heavily on features, quality comparisons, and generating content. However, practical considerations such as licensing and usage rights are equally important for anyone planning to publish content online.

One thing I noticed while researching was that some tutorials rarely discuss restrictions that may apply to commercially using AI-generated media. For creators who hope to monetise their work in the future, understanding these terms is just as important as learning how to use the tools themselves.

I also came across suggestions that users could maximise free quotas by creating and using multiple accounts. While such approaches may appear attractive, I preferred to understand the official usage policies and evaluate the tools based on legitimate usage scenarios.

Another common pattern was videos claiming ways to use certain services "for free" or "without limits," often encouraging viewers to watch until the end for the explanation. In many cases, the actual advice was far less significant than the promise made at the beginning of the video.

These experiences reminded me that evaluating AI tools involves more than comparing features and outputs. It is also important to understand licensing terms, usage limits, subscription costs, and whether a workflow remains practical and sustainable in the long term.

This was an important reminder that content creation involves more than the creative process alone.


Animation Was Not Automatic

Before starting, I assumed animation would be one of the simplest stages.

In reality, it required continual review and adjustment.

Some generated clips worked well, while others required regeneration or modification.

Common challenges included:

  • Motion inconsistencies.
  • Visual artefacts.
  • Timing issues.
  • Scene continuity.

Rather than generating one perfect clip, the process often involved creating multiple alternatives and selecting the most suitable version.

The role felt less like pressing a button and more like directing a production.


The Unexpected Importance of Organisation

One of the biggest surprises had nothing to do with AI.

As the project progressed, the number of assets grew rapidly. What started as a simple storytelling exercise gradually expanded into a collection of story drafts, narration files, images, animated clips, alternate versions and working notes.

For a period, my approach was not particularly organised. Files were being created quickly, new versions were being generated, and multiple alternatives were being evaluated. As the volume of content increased, I occasionally found myself spending more time locating files, comparing versions and retracing earlier decisions than I expected. The growing number of assets started to feel slightly overwhelming.

I found myself managing:

  • Story drafts.
  • Narration files.
  • Images.
  • Animated clips.
  • Alternate versions.
  • Working notes.

Good organisation soon became essential rather than optional.

Simple practices such as maintaining structured folders, clear file names and consistent version control saved a considerable amount of time throughout the project.

In hindsight, establishing these practices earlier would have reduced confusion and made the workflow more efficient from the start. Without this organisation, managing the project would have become increasingly difficult as additional scenes and revisions were added.


Reality vs Expectations

Looking back, the differences between expectations and reality were quite clear.

ExpectationReality
Complete the project in a few hoursTook approximately 2–3 days
Mostly automated processContinuous review and refinement
Easy image creationMultiple prompt revisions required
Simple narration generationSignificant testing and adjustments
AI does most of the workRoughly 50% AI and 50% human effort
Generate and publishFull production workflow

Lessons Learned

Reflecting on the project, several lessons stand out.

AI Works Best as a Creative Partner

AI was most effective when treated as a collaborator rather than an autonomous creator.

The quality of the results improved significantly when clear direction and feedback were provided.

Simplicity Can Be Powerful

The folk tale itself was extremely simple, yet it carried a meaningful lesson.

This project reinforced the idea that engaging stories do not need to be complex.

Consistency Is Harder Than Creation

Generating content is often easier than maintaining consistency across an entire project.

Keeping characters, scenes, styles, and pacing aligned required far more effort than I initially expected.

Organisation Is Essential

As content and assets accumulate, organisation quickly becomes a critical skill.

Good file management saved time and reduced confusion throughout the project.

Building a Workflow Is More Valuable Than Building One Video

Perhaps the most valuable outcome was not the finished video itself but the process developed along the way.

The experience helped establish a repeatable workflow that can be improved and reused for future projects.


Tools Used

PurposeTool
Story DevelopmentClaude
Visual Generation and AnimationGoogle Flow
Voice GenerationElevenLabs
Video EditingClipchamp
PublishingYouTube Studio

Was It Worth It?

Absolutely.

The project was harder than I expected, but it was worth the effort.

Beyond creating a finished video, I gained:

  • A better understanding of AI-assisted storytelling.
  • Practical experience using Google Flow.
  • Knowledge of licensing considerations.
  • Improved content organisation skills.
  • A repeatable workflow for future projects.

Most importantly, I gained a realistic perspective on what AI can and cannot do within a content creation workflow.


What's Next?

This project is only one step in my AI learning journey.

Future projects will focus on refining the workflow, improving scene consistency, exploring different storytelling formats, and continuing to learn where AI can genuinely add value.

Each project brings new lessons, and that ongoing learning process is becoming just as rewarding as the finished videos themselves.


Final Thoughts

When I started this project, I believed AI would create an animated story for me.

Instead, I discovered something much more interesting.

AI acted as a creative partner rather than a replacement.

It accelerated many parts of the process, generated ideas, assisted with production, and reduced repetitive work. However, the final result still depended heavily on human judgement, decision-making, and persistence.

What began as a simple folk tale became a practical lesson in storytelling, content creation, project organisation, and AI-assisted production.

Most importantly, it provided a realistic understanding of how humans and AI can work together to create something meaningful.

The project took longer than expected, but the learning experience made every hour worthwhile.



Friday, December 4, 2026

My First AI-Assisted Video: Reality vs Hype

 A hands-on case study of what it really took: the time, the cost and the mistakes.


This post is for beginners who want to use AI to make YouTube videos. If you're wondering whether you can do it, you probably have the same four questions I had before I started:

1. How simple or how difficult will it be?

2. How long will it take?

3. Will AI make it easy?

4. How much will it cost me?

Here's what actually happened when I made my first video.




Watch it on YouTube: https://youtu.be/CUtDueKwTH8


Why I picked this topic

I chose something I already know: home water and plumbing tips for the UAE, from my own work experience. That way I could read the AI-written script and fix anything that sounded wrong. I wanted my energy to go into learning the tools, not learning the subject.


What I did (in order)


1. Picked a simple topic from my own work.

I chose a topic I already knew well: home water and plumbing tips for the UAE. That allowed me to focus on learning the AI and video tools rather than learning a new subject.

2. Planned the format.
I aimed for a five-minute video in English, presented step by step. The finished video came out at just over three minutes.

3. Chose the topic.
AI suggested a list of topics. From the list of suggestions, I selected Home Water-Saving Checks.

 

4. Created and revised the script.
AI generated a script of about 650 words, which I then reviewed and corrected.

5. Generated the voiceover.
I used ElevenLabs on the free plan to create the narration.


6. Found the visuals.
Most of the video clips came from Pexels. When I couldn't find suitable footage, I used Pixabay photos and added pan-and-zoom effects to create movement.

7. Created a checklist slide.
I built a simple checklist graphic with Claude's help.

8. Edited everything in Clipchamp.
I combined the voiceover, visuals, captions and safety text into the final video. I chose not to use background music.

9. Created the thumbnail.
I started with a frame from the video and later added text to it in Canva.


10. Exported and reviewed the video.
I exported the final video as a 1080p MP4 and watched it through before uploading.

11. Changed the visibility from Private to Public.


Clipchamp editing timeline showing video clips, photos and the AI voiceover tracks for the water-saving video
My Clipchamp timeline: stock clips, photos with pan and zoom, and the voiceover tracks.




Slide titled "Your 5-Minute Water Checklist" listing four water-saving checks
The checklist slide I made with Claude's help.



What didn't go smoothly

Clips that didn't fit. For some lines of my script, I couldn't find a suitable matching clip. I did not want to spend a long time searching for video clips that matched my content. So I decided to use Photos with pan and zoom to fill the gaps. I later learned this is called the Ken Burns effect. I watched some videos of Ken Burns's The Civil War to see the art of doing it well.

No speed control in ElevenLabs V4. I wanted the voice a little slower while trying V4. But that version didn't have an option to control the voice speed. To get the option of voice speed control, I had to use V2, and it worked well. I generated the voiceover and saved the audio files in a folder.

Confusing plan names and credits. What does "Starter" actually include? How many minutes of audio is a credit? On the plan page I checked, roughly 1,000 credits equals one minute of speech. The free plan gives about 10 minutes a month, and Starter about 30.


ElevenLabs plan comparison with Free and Starter highlighted, showing minutes included and commercial use
ElevenLabs plans as of 3 December 2026. Prices and limits change, so check the site.


Picture sizes.
I started with images of 1920×1080 px. When the same-sized images were not easily found I had to select images that were slightly off that size (say about 1920×1058). Small differences did not matter much; the result of the Ken Burns effect turned out fine.

Pictures that weren't quite right. Some of my images weren't perfect, and I used them anyway. I wanted to reach the finish line once and see the whole process work. Otherwise I'd still be fixing things.

The thumbnail. My first thumbnail had no words, so I added them in Canva. The PNG file was 3.9 MB, and YouTube's limit is 2 MB. Saving it as a JPG brought it down to about 265 KB.

The upload screens. These confused me most, especially the AI-disclosure question and the private/public setting. Here are the steps, as simply as I can put them:

  1. Go to YouTube Studio, click Create, then Upload videos.
  2. Pick your video file.
  3. Add a title, a description and a thumbnail.
  4. Say whether the video is made for kids. Mine wasn't.
  5. Answer the AI question. I chose Yes, because the voiceover is made by AI, even though the clips are real stock footage. Yes adds a small label to the video, and I'm fine with that.
  6. Click Next through the remaining pages, then choose who can see the video (Private, Unlisted or Public) and click Publish (or Save).

YouTube upload screen asking whether AI was used, with Yes selected
The AI-use question on YouTube's upload screen. I answered Yes.

A licensing lesson I learned late

After finishing the video, I learned that ElevenLabs' free plan doesn't allow commercial use. Free-plan audio also needs a credit to ElevenLabs in the video title. So I added "elevenlabs.io" to my title and signed up for the $6-a-month Starter plan for future videos.

Pexels and Pixabay say credit is optional, not mandatory, but contributors appreciate it. So I credited them in the description anyway.

The lesson: check the license before you start, not after.

Hype versus reality

The hype: AI makes the whole video for you in minutes.
The reality: AI helped with the script and the voice. I still chose the topic, corrected the script, hunted for clips and photos, fixed the pacing, and worked out the licensing and upload settings myself.

The hype: it's a cakewalk.
The reality: it's easy to start, and harder to get the details right.

The hype: it takes no money.
The reality: the video cost me nothing extra, but I ended up paying $6 a month once I understood the commercial licensing requirement for ElevenLabs.

How long it took

Almost three days. And not because the video itself was long. Most of that time went into learning: trying out the video tools, working out picture sizes and reading the documentation. My next video should go faster, because I won't be learning everything from zero again.

What it cost

The video itself cost nothing extra. I already pay US$9.99 for one month of Office 365 for Excel and Word, and Clipchamp comes with it. The voiceover used ElevenLabs' free plan, and the clips and photos were free. After finishing, I subscribed to ElevenLabs Starter at US$6 a month, so for a beginner the real cost of getting started is about $6 a month.

Was it easy?

You'll see a lot of YouTube videos that make it look like a cakewalk. For a beginner with no experience, it isn't. It's easy to start, and harder to get the details right.

Where I ended up

My first video is a bit half-cooked, and I've left it on YouTube on purpose. Years from now I want it there as a reminder of where I started. If you're a beginner, don't wait until it's perfect. Make one, finish it, and learn from it.

Credits: Voiceover: elevenlabs.io. Video clips: Pexels contributors, via pexels.com. Photos: Pixabay contributors, via pixabay.com. 3D model image: Printables (public domain, CC0).

Note: I used AI tools to help organize and edit this post. The experience, the decisions and the mistakes are my own.

Media Attribution: A complete list of media sources used in this project is available in the [Media Attribution Library].

Wednesday, January 15, 2025

Power Query Function Signatures Explained: A Beginner's Guide to IntelliSense




When you're working with Power Query's M code, you might notice that when you start typing a function, a small pop-up (called IntelliSense) appears, showing you how to use that function. This pop-up shows a "function signature," which is like a quick instruction manual for the function.

List.Transform
List.Transform(list as list, transform as function) as list
What does it mean when you see something like this.

Part 1 of the code:



list as list: This means the first thing you need is a list (a collection of items like numbers or text).




























Part 2 of the code:




transform as function: This means the second thing you need is a function (a rule or formula) that tells how to change each item in the list.
































Part 3 of the code:















This visually connects the idea that you're taking a list, applying a rule, and getting a new list as a result.

Friday, December 27, 2024

Power Query Date Transformations: A Beginner's Guide with M Code Examples







Mastering Date Transformations in Power Query: A Beginner’s Guide to M Code


Transforming and analyzing date-related data is an essential skill when working with Power Query in Excel. Whether you're creating custom columns to extract the name of the month, the day of the week, or performing other date-related transformations, mastering M Code can take your data analysis to the next level. But don’t worry if you’re new to Power Query — we’ll simplify everything for you!


In this blog post, we’ll dive deep into the world of date transformations using Power Query. Starting with the basics, we’ll walk you through how to extract specific details, such as abbreviations for months and days, and explore other useful transformations to make your data more meaningful. With easy-to-understand explanations, step-by-step M Code examples, and practical use cases, this guide will help you unlock the full potential of date data in Power Query.

By the end of this blog, you'll not only understand how to manipulate date columns effortlessly but also gain confidence in writing M Code to achieve customized transformations. Let’s get started and make date transformations in Power Query as easy as a few clicks!

1. Extract the Year from the Date

This transformation creates a new column that extracts the year from the [Date] column.


M Code:


= Table.AddColumn(#"PreviousStepName", "Year", each Date.Year([Date]), type number)

Output Example:

Date Year
2023-05-12 2023
2023-06-15 2023
2024-01-01 2024





Power Query table showing the Date column and a new Year column created with Date.Year


2. Extract the Month Number

This transformation creates a new column that extracts the numeric value of the month (e.g., 1 for January, 2 for February).


M Code:


= Table.AddColumn(#"PreviousStepName", "Month_Number", each Date.Month([Date]), type number)

Output Example:

Date Month_Number
2023-05-12 5
2023-06-15 6
2024-01-01 1

3. Extract the Week Number

This transformation creates a column to show the week number of the year for each date.


M Code:


= Table.AddColumn(#"PreviousStepName", "Week_Number", each Date.WeekOfYear([Date]), type number)

Output Example:

Date Week_Number
2023-05-12 19
2023-06-15 24
2024-01-01 1

4. Extract the Day Number

This transformation creates a new column showing the day number of the month for each date.


M Code:


= Table.AddColumn(#"PreviousStepName", "Day_Number", each Date.Day([Date]), type number)

Output Example:

Date Day_Number
2023-05-12 12
2023-06-15 15
2024-01-01 1

5. Is the Date a Weekend?

This transformation creates a column to indicate whether the date falls on a weekend (Saturday or Sunday).


M Code:


= Table.AddColumn(#"PreviousStepName", "Is_Weekend", each Date.DayOfWeek([Date], Day.Monday) >= 5, type logical)

Output Example:

Date Is_Weekend
2023-05-12 false
2023-05-13 true
2023-05-14 true

6. Find the Quarter of the Year

This transformation creates a column showing the quarter of the year (e.g., Q1, Q2, Q3, Q4).


M Code:


= Table.AddColumn(#"PreviousStepName", "Quarter", each "Q" & Text.From(Date.QuarterOfYear([Date])), type text)

Output Example:

Date Quarter
2023-05-12 Q2
2023-06-15 Q2
2024-01-01 Q1

7. Day of the Year

This transformation calculates the day number of the year for each date (e.g., January 1 is day 1, December 31 is day 365 or 366).


M Code:


= Table.AddColumn(#"PreviousStepName", "Day_Of_Year", each Date.DayOfYear([Date]), type number)

Output Example:

Date Day_Of_Year
2023-05-12 132
2023-06-15 166
2024-01-01 1

8. Add Custom Date Formats

This transformation creates a column that formats the date in a specific way (e.g., MM/dd/yyyy).


M Code:


= Table.AddColumn(#"PreviousStepName", "Custom_Date_Format", each Text.PadStart(Text.From(Date.Month([Date])), 2, "0") & "/" & Text.PadStart(Text.From(Date.Day([Date])), 2, "0") & "/" & Text.From(Date.Year([Date])), type text)

Output Example:

Date Custom_Date_Format
2023-05-12 05/12/2023
2023-06-15 06/15/2023
2024-01-01 01/01/2024

9. First Day of the Month

This transformation calculates the first day of the month for each date.


M Code:


= Table.AddColumn(#"PreviousStepName", "First_Day_Of_Month", each Date.StartOfMonth([Date]), type date)

Output Example:

Date First_Day_Of_Month
2023-05-12 2023-05-01
2023-06-15 2023-06-01
2024-01-01 2024-01-01

10. Last Day of the Month

This transformation calculates the last day of the month for each date.


M Code:


= Table.AddColumn(#"PreviousStepName", "Last_Day_Of_Month", each Date.EndOfMonth([Date]), type date)

Output Example:

Date Last_Day_Of_Month
2023-05-12 2023-05-31
2023-06-15 2023-06-30
2024-01-01 2024-01-31

11. Weekday Number (0 = Sunday, 6 = Saturday)

This transformation creates a column showing the day of the week as a number (0 for Sunday, 1 for Monday, etc.).


M Code:


= Table.AddColumn(#"PreviousStepName", "Weekday_Number", each Date.DayOfWeek([Date], Day.Sunday), type number)

Output Example:

Date Weekday_Number
2023-05-12 5
2023-05-13 6
2023-05-14 0

12. Custom Weekday Labels

This transformation allows you to create a custom weekday label for each date.


M Code:


= Table.AddColumn(#"PreviousStepName", "Custom_Weekday_Label", each if Date.DayOfWeek([Date], Day.Monday) >= 5 then "Weekend" else "Weekday", type text)

Output Example:

Date Custom_Weekday_Label
2023-05-12 Weekday
2023-05-13 Weekend
2023-05-14 Weekend


Some Advanced M Code functions related to Date Transformations:


To extract the Name of the Month (e.g., Jan from the date 2023-01-15) from the date in the given example, you can use the Date.MonthName function in Power Query (M code). Below is the M code to accomplish this:

DateMonth
2023-01-15Jan
2023-02-20Feb
2023-03-10Mar

M Code:

= Table.AddColumn(#"Added Custom", "Month", each Text.Start(Date.MonthName([Date]),3), type text)


Detailed Parsing:

1 ) = Table.AddColumn(
  • Meaning: This is a function in Power Query (M language) that adds a new column to an existing table.
  • Action: It specifies that you are adding a new column to the table from the previous step.
    2) #"Added Custom"
    • Meaning: This is the name of the table from the previous step in your query. In Power Query, steps are often referenced by their names.
    • Action: The function will add the new column to this table. This is a reference to an existing table.
      3) "Month",
      • Meaning: This is the name of the new column that will be added to the table.
      • Action: A new column named "Month" will be created.
        4) each
        • Meaning: This is a keyword in Power Query that is used to apply a function to each row of the table.
        • Action: It signals that the operation defined next should be applied to each row in the table.
          5) Text.Start(
          • Meaning: This is a function that returns a specified number of characters from the start of a text string.
          • Action: The function will extract the first few characters from the result of Date.MonthName.
            6) Date.MonthName([Date])
            • Meaning: The Date.MonthName function returns the full name of the month (e.g., "January", "February") for the value in the [Date] column.
            • Action: For the given row's [Date] value, this extracts the name of the month.
              7) [Date]
              • Meaning: This is a reference to the column named "Date" in the current row.
              • Action: The function takes the value in the [Date] column of the current row and uses it as input for Date.MonthName.
                8) 3),
                • Meaning: This specifies the number of characters to extract from the text returned by Date.MonthName. For example, "January" becomes "Jan".
                • Action: Only the first 3 characters of the month name are extracted.
                  9)  type text
                  • Meaning: This specifies the data type of the new column being added. In this case, the column will contain text values.
                  • Action: Ensures that the new column "Month" is of the text data type.

                  Full Explanation in Plain English:
                  Step 1: The function starts by referencing the table from the previous step (called #"Added Custom").
                  Step 2: A new column named "Month" will be added to this table.
                  Step 3: For each row in the table:
                  • The Date.MonthName([Date]) function retrieves the full name of the month (e.g., "January", "February") from the value in the [Date] column.
                  • The Text.Start function then extracts the first 3 characters of the month name (e.g., "Jan" from "January").
                  Step 4: The new column is defined as text using type text.



                  Improved and Commented M Code:

                  Here’s the same M code with inline comments (in Blue) for clarity:

                  = Table.AddColumn(#"Changed Type",/* Reference to the previous step/table in the query */

                  "Custom", /* Name of the new column to be added */

                  each Text.Start( /* Apply the following function to each row */

                  Date.MonthName([Date]), /* Get the full month name from the "Date" column */

                  3 /* Extract only the first 3 characters (e.g., "Jan" from "January") */

                  ), type text)

                  M Code Made Easier for a Layman:

                  Here’s how this code works step by step in simple terms:

                  1. Imagine you have a table with dates in one column (e.g., "2023-01-15").
                  2. You want to add a new column to this table that shows the first three letters of the month (e.g., "Jan").
                  3. The M Code:= Table.AddColumn(#"Added Custom", "Month", each Text.Start(Date.MonthName([Date]),3), type text):
                  • Looks at each row in the table.
                  • Takes the date from the [Date] column.
                  • Converts the date into the full month name (e.g., "January").
                  • Extracts the first three letters (e.g., "Jan").
                  • Adds this result as a new column called "Month".
                  • Finally, it ensures that the new column contains text values.

                  What You’ll See in Power Query:

                  After applying this code, the table will look something like this:

                  DateMonth
                  2023-01-15Jan
                  2023-02-20Feb
                  2023-03-10Mar

                  To extract the day number (e.g., 15 from 2023-01-15) from the date in the previous example, you can use the Date.Day function in Power Query (M code). Below is the M code to accomplish this:

                  M Code:

                  = Table.AddColumn( #"Added Custom", // Reference to the previous step/table in the query "Day", // Name of the new column to be added each Date.Day([Date]), // Extract the day number from the "Date" column Int64.Type // Specify the data type as an integer )

                  Explanation:

                  1. Table.AddColumn:

                    • This function adds a new column to the table.
                  2. #"Added Custom":

                    • This is the name of the table from the previous step in the query.
                  3. "Day":

                    • The name of the new column that will contain the extracted day numbers.
                  4. each Date.Day([Date]):

                    • The Date.Day function retrieves the day number (e.g., 15 from 2023-01-15) from the [Date] column for each row.
                  5. Int64.Type:

                    • This sets the data type of the new column to a 64-bit integer, which is suitable for day numbers.

                  Result:

                  After applying this code, your table will look like this:

                  DateDay
                  2023-01-1515
                  2023-02-2020
                  2023-03-1010

                  For a Layman:

                  This code will:

                  • Add a new column to your table.
                  • Look at the [Date] column for each row.
                  • Extract the day number from the date (e.g., 15 for January 15, 2023).
                  • Add this number as a new column called "Day".


                  Let's break down the provided M Code step by step, add commentary to guide you, and provide an easy-to-understand explanation for what it does:


                  M Code:

                  = Table.AddColumn(#"Added Custom", "Day_Of_Week", each Text.Start(Date.DayOfWeekName([Date]),3), type text)

                  Step-by-Step Parsing and Commentary:

                  1. = Table.AddColumn:

                    • This is a function in Power Query used to add a new column to an existing table.
                    • The new column will be calculated based on the logic provided in the code.
                  2. #"Added Custom":

                    • This is a reference to the previous step in your query. In Power Query, every step is named (either automatically or manually by you).
                    • In this case, "Added Custom" refers to the name of the table/output from the previous step.
                  3. "Day_Of_Week":

                    • This is the name of the new column being created.
                    • The new column will store the abbreviated names of the days of the week (e.g., "Mon", "Tue", "Wed").
                  4. each:

                    • This is a keyword in Power Query that is used to apply the subsequent logic to each row in the table.
                    • It essentially means "perform the following operation on every row in the table."
                  5. Date.DayOfWeekName([Date]):

                    • This is a Power Query function that retrieves the full name of the day of the week for the value in the [Date] column.
                    • For example:
                      • If [Date] is 2023-05-12, this function will return "Friday".
                      • If [Date] is 2023-05-13, this function will return "Saturday".
                  6. Text.Start(..., 3):

                    • The Text.Start function takes the result of Date.DayOfWeekName (e.g., "Friday") and extracts the first 3 characters.
                    • For example:
                      • "Friday" becomes "Fri".
                      • "Saturday" becomes "Sat".
                    • This is how you get the abbreviated day names in the new column.
                  7. type text:

                    • This specifies that the data type of the new column should be text.
                    • This ensures that the values in the "Day_Of_Week" column are stored as text (e.g., "Mon", "Tue").

                  What Does This Code Do?

                  • The code creates a new column called "Day_Of_Week".
                  • For each row in the table:
                    1. It looks at the value in the [Date] column.
                    2. It calculates the full day name (e.g., "Monday" or "Tuesday") using the Date.DayOfWeekName function.
                    3. It extracts the first 3 characters of the day name (e.g., "Mon", "Tue") using the Text.Start function.
                    4. The result is stored in the new column as text.

                  Example:

                  If your table initially looks like this:

                  Date
                  2023-05-12
                  2023-05-13
                  2023-05-14

                  After applying the M Code, it will look like this:

                  DateDay_Of_Week
                  2023-05-12Fri
                  2023-05-13Sat
                  2023-05-14Sun

                  For Beginners:

                  This code will:

                  1. Create a new column called "Day_Of_Week".
                  2. For each row, look at the date in the [Date] column.
                  3. Figure out the day of the week (e.g., "Monday" or "Friday") for the date.
                  4. Take the first 3 letters of the day (e.g., "Mon" or "Fri").
                  5. Save this value as text in the new column.

                  Notes:

                  • Make sure the [Date] column in your table contains valid date values.
                  • If the [Date] column contains invalid data (e.g., text or null values), you may encounter errors.

                  Wednesday, December 25, 2024

                  Mastering-power-query-m-code-a-beginners-guide-to-learning-and-transforming-data-in-excel-and-power-bi

                  Mastering Power Query M Code: A Beginner's Guide to Simplify Data Transformation







                  Are you finding it challenging to manipulate and transform data in Power Query using M code? If so, you're not alone. M language, the backbone of Power Query in Excel and Power BI, can seem intimidating at first, but with the right strategy and resources, you can master it and unlock its true potential. This guide provides a structured approach to learning M code, complete with practical examples and tips to help you build confidence and fluency.


                  1. Start with the Basics: Understand Power Query

                  Before diving deep into M code, get familiar with the fundamentals of Power Query:

                  • Use the Power Query interface in Excel or Power BI to learn the basics of loading, transforming, and combining data.
                  • Perform actions like filtering rows, sorting data, and renaming columns. These generate M code automatically in the background, which you can study in the Advanced Editor.

                  Key Tip: Start small and gradually explore more complex operations as you gain confidence.


                  2. Break Down and Analyze Queries

                  Each query in Power Query generates M code. Use this as a learning opportunity:

                  1. Load a dataset into Power Query.
                  2. Perform basic operations like removing duplicates or renaming columns.
                  3. Open the Advanced Editor to view the M code generated for these steps.
                  4. Experiment with modifying the code in the editor to understand how it affects your query.

                  By doing this, you'll start to recognize patterns and common functions used in M code.


                  3. Master Key Concepts of M Language

                  a. Understand the Data Structures

                  M code revolves around three key structures:

                  • Tables: Used for structured, tabular data.
                  • Records: Represent single rows or objects.
                  • Lists: Single-column collections of data (like arrays).

                  Learn the functions used to manipulate these structures, such as:

                  • Table.AddColumn
                  • Table.SelectRows
                  • Table.Group
                  • List.Combine
                  • List.Sort
                  • List.Transform
                  • Record.FieldValues
                  • Record.ToTable

                  b. Learn the Function Syntax

                  Most M functions follow this structure:


                  FunctionName(parameter1 as type, parameter2 as type, ...) as returnType


                  For example:

                  Table.SelectRows(table as table, condition as function) as table

                  c. Explore Commonly Used Functions

                  Get comfortable with frequently used functions in M:

                  • Text Functions: Text.Upper, Text.Length, Text.Split
                  • Number Functions: Number.Round, Number.Mod
                  • Table Functions: Table.TransformColumns, Table.RemoveColumns
                  • List Functions: List.Sum, List.Distinct, List.Accumulate

                  4. Practice with Real-World Scenarios

                  Applying M code to real-world data challenges is the best way to build your skills. Here are a few examples:

                  Scenario 1: Cleaning Data

                  • Remove extra spaces, fix text case inconsistencies, or extract specific data from messy columns.

                  Scenario 2: Combining Data

                  • Append or merge multiple tables from different sources, such as Excel files or CSVs.

                  Scenario 3: Dynamic Calculations

                  • Add calculated columns to tables for custom metrics or aggregated data.

                  Scenario 4: Reshaping Data

                  • Use pivot and unpivot operations to transform data into the desired structure.

                  5. Use Resources to Deepen Your Knowledge

                  a. Official Documentation

                  The Power Query M Language Reference by Microsoft is the go-to resource for M code syntax and functions.

                  b. Video Tutorials

                  Search for Power Query tutorials on YouTube. Popular creators like Guy in a Cube, Chandoo, and ExcelIsFun often explain M code concepts clearly.

                  c. Books

                  • M is for (Data) Monkey by Ken Puls and Miguel Escobar
                  • Power Query for Power BI and Excel by Christopher Webb

                  d. Forums and Communities

                  • Microsoft Power Query Forum
                  • Power BI Community

                  6. Experiment with Custom Functions

                  Once you've grasped the basics, create your own custom functions for reusable operations.

                  For example, a function to calculate discounts:

                  let CalculateDiscount = (Price as number, DiscountRate as number) => let DiscountAmount = Price * DiscountRate, FinalPrice = Price - DiscountAmount in FinalPrice in CalculateDiscount

                  7. Build a Cheat Sheet

                  Create a personalized cheat sheet to quickly reference M code syntax and common functions. This will save time and make learning more structured.


                  8. Debug and Experiment

                  The best way to learn M code is by trial and error:

                  • Use Power Query to create queries, then debug and modify them in the Advanced Editor.
                  • Explore the #shared function to discover built-in M functions and their descriptions.

                  9. Share Your Knowledge

                  One of the best ways to solidify your understanding is by teaching others.
                  Consider writing blogs, recording tutorials, or sharing tips on forums.


                  10. Stay Consistent

                  Learning M code takes time, so practice consistently. Dedicate 30 minutes daily to working on small challenges or exploring new functions.


                  Conclusion

                  Mastering Power Query M code can transform the way you handle data. By understanding the fundamentals, practicing real-world scenarios, and leveraging available resources, you’ll be able to clean, transform, and analyze data efficiently. Whether you're a data analyst, business professional, or Excel enthusiast, these skills will give you a significant edge in your field.


                  This guide was created with the help of ChatGPT to provide you with a comprehensive learning path. Feel free to share it with others who might benefit! 😊