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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
YmmotEul
Frequent Visitor

How to Create a new column that adds the Month for specific number of rows?

First of all, thanks for helping me!

My help needed is as below: 
For example: i have 3 countries to take care of : (Thailand, America, China) as shown below. I am recording the no. of accidents and the headcount for each month.

From my raw data below, it didnt have a "Date" as highlighted originally. I would like to create a new column in PowerBI and to add the monthly date e.g. Jan-23 for the first 3 rows, Feb-23 for the subsequently 3 rows after the first three. etc etc until December 2023.  May i know how should i do this during the power query in PowerBI to add new column? 

Thanks! 

image.png

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@YmmotEul , In power Query first add an index column starting with 0

Index Column: https://youtu.be/NS4esnCDqVw

 

Then add a new column in power query

 Date.AddDays(#date(2023,01,01) , Number.IntegerDivide([Index],3))

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Is there no column in your dataset from where a date can be created i.e. columns such as Month number/Month name/Year?  Anyways, share the dataset in a format that can be pasted in an MS Excel file.


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

Hi 

From Amit;'s solution, i changed from 

 Date.AddDays(#date(2023,01,01) , Number.IntegerDivide([Index],3))    ->>>>> Date.AddMONTHS and it worked. 


YmmotEul
Frequent Visitor

Dear Amit, The dates it returned was all January 2023 i.e. The first 3 rows are 1-jan, the next 3 rows are 2-Jan, where the next 3 rows should have been 1-Feb. 

Thanks could you take a look again on this?

amitchandak
Super User
Super User

@YmmotEul , In power Query first add an index column starting with 0

Index Column: https://youtu.be/NS4esnCDqVw

 

Then add a new column in power query

 Date.AddDays(#date(2023,01,01) , Number.IntegerDivide([Index],3))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.