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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

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