Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
deanbland
Helper III
Helper III

Adding Column to Power Query

Hi, 

 

I am trying to add a column to Power Query that says "Yes" or "No" depending on whether it is the current month or not. 

 

What I am trying to do is compare the current month's rag status with last months in one table. This is proving to be a challenge and so this is the only way I can think to do it? 

 

A sample dataset is below 

 

Activity IDExport Date

DAI RAG

DAI Title

3177406/01/20211Team
3177406/01/20211Schedule
3177406/01/20211Project
3177406/02/20212Team
3177406/02/20212Schedule
3177406/02/20212Project

 

What the visual table will look like 

 

DAI TitleCurrent MonthPrevious Month
Team12
Schedule12
Project12

 

If you can see a better way to do this then please do let me know! 

 

Thanks 🙂 

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Please see this video on how to add a yearmonth index column centered on today to your date table.  If you don't have a date table, adding one makes your life easier (see 2nd link).

Power BI Tales From The Front - Day/Week/Month/Quarter/Year Indices - YouTube

Creating a simple date table in DAX - SQLBI

 

You can then make a measure that calculates your expression in two variables (one with YearMonthIndex = 0 and the other = -1 and then use both variables in your Return to compare them.

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

You could write two measures like this

 

Current Month = CALCULATE(SUM(Table[DAI RAG]), Date[YearMonthIndex] = 0)
Prev Month = CALCULATE(SUM(Table[DAI RAG]), Date[YearMonthIndex] = -1)

 

Another way to do it would be to make a matrix visual with DAI Title on Rows, YearMonthIndex on Columns, and drag the DAI RAG column to the Values and choose Sum aggregation.  You can then use the Filter panel to filter YearMonthIndex to between 0 and -1.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Microsoft Employee
Microsoft Employee

Please see this video on how to add a yearmonth index column centered on today to your date table.  If you don't have a date table, adding one makes your life easier (see 2nd link).

Power BI Tales From The Front - Day/Week/Month/Quarter/Year Indices - YouTube

Creating a simple date table in DAX - SQLBI

 

You can then make a measure that calculates your expression in two variables (one with YearMonthIndex = 0 and the other = -1 and then use both variables in your Return to compare them.

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi @mahoneypat

 

Thank you for that - the Month Index is working a treat. My question is, how would I translate this into measures that return current and past months? I can't seem to figure out how to create the table in the above post that compares current to past. 

 

Thanks again! 

You could write two measures like this

 

Current Month = CALCULATE(SUM(Table[DAI RAG]), Date[YearMonthIndex] = 0)
Prev Month = CALCULATE(SUM(Table[DAI RAG]), Date[YearMonthIndex] = -1)

 

Another way to do it would be to make a matrix visual with DAI Title on Rows, YearMonthIndex on Columns, and drag the DAI RAG column to the Values and choose Sum aggregation.  You can then use the Filter panel to filter YearMonthIndex to between 0 and -1.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.