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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Add rows based on condition

Hi everyone,

I am looking for a solution to add new rows to my dataset.
For each Month of each value of [Country Name], I need to ensure that there is a row where [Business] = "Mining". If it does not in dataset, I need to add a new one. As in the picture below, there is row for every month of Country1, but only row for January and December of Country2. So I need to add more 10 rows (from February to November). However, it possibly required 3 or different number of rows for other [Country Name] value, or might be none (if like Country1).

addrowcondition.GIF

I tried to divide this problem into small steps, both in Power Query or DAX, but till now I cannot find any reasonable solution. 

Any help from you would be so valuable to me!

Thank you!

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

In Edit queries, i create a date table as below

Capture10.JPG

enter dates in box "startdate" and "enddate", then "Invoke", we can get a new table, renamed it as "date",

Capture11.JPG

Then in your table, if you only have three columns, group data as below,

Capture12.JPG

Then add a custom column and expand

Capture13.JPGCapture14.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

In Edit queries, i create a date table as below

Capture10.JPG

enter dates in box "startdate" and "enddate", then "Invoke", we can get a new table, renamed it as "date",

Capture11.JPG

Then in your table, if you only have three columns, group data as below,

Capture12.JPG

Then add a custom column and expand

Capture13.JPGCapture14.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-juanli-msft  thank you Juan li, there are much power query techniques on it and I have learned a lot. Very sorry for the late reaction.

lc_finance
Solution Sage
Solution Sage

Hi @Anonymous ,

 

 

I think the easiest solution is the generate a new table in DAX with all the necessary rows.

 

You can create a new calculated table in Power BI with the following formula:

Country by month table = GENERATEALL(VALUES(Table1[Country Name]),VALUES(Table1[Calendar]))

You can then add columns to this new table and copy there any values from your previous table.

 

Does this help you?

 

LC

Interested in Power BI and DAX templates? Check out my blog at www.finance-bi.com

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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