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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jimboj
Regular Visitor

Insert Row using an IF Statement

I have a database I connect using Power Query, which brings in monthly data for analyzation and reporting. In some months I have a Revenue Code that may show up or may not. What I would like to do is create an IF function that looks for this Code and inserts a row for that Code if not present. 

 

My current line of code: = Table.InsertRows(#"Reordered Columns", 2, {[Revenue Code="104", Date= null, kWh= null, kW= null, Charges= null, Tax= null, Total= null]})

 

But the problem is in months that Code 104 is created, it doubles the count further in queries. SO my thoughts were to create an If function that crerates the above data if the code is missing but ignores it if it is present.

 

Thank you for any assistance.

1 REPLY 1
KNP
Super User
Super User

This would be much easier to solve with some sample data.

 

You could possibly just add a grouping to deal with the duplicate rows.

So, group by everything you need to and do a max or sum of the Date, kWh, KW, Charges etc. as required.

This should give you what you want. Again, can't be sure without seeing some sample data.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors