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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Dynamic Formula for Power Query

Hello All

 

I have a column called "Period ID" and need to replace Period ID 65 with 122. I am using this formula which works fine:

 

= Table.ReplaceValue(#"Replaced Value2",each [PeriodId], each if [PeriodId]=65 and [ApplicationId]>=34 and [ApplicationId]<=36 then 122 else [PeriodId],Replacer.ReplaceValue,{"PeriodId"})

 

The problem I have is this report pulls from an SQL database once a week bringing in new data. Therfore the Period ID changes each week. This week it is 65 and next week it will be 66, the week after 67. The same goes for the replacement value, this week it is 122, next week it will be 123 and so on. Is there a way I can set the formula so that it dynamically changes each time the Period ID Changes. This week replace 65 with 122, next week replace 66 with 123, etc.? I have to keep the ApplicationIDs in the formulas as show above since they target which lines needs changed. Thanks for any help!

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

If this week, week number 41 is the one you take as base, then:

 

= Table.ReplaceValue(#"Replaced Value2",each [PeriodId], each if [PeriodId]=65+Date.WeekOfYear(DateTime.LocalNow())-41 and [ApplicationId]>=34 and [ApplicationId]<=36 then 122+Date.WeekOfYear(DateTime.LocalNow())-41 else [PeriodId],Replacer.ReplaceValue,{"PeriodId"})

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

5 REPLIES 5
rogletree
Helper III
Helper III

I'm just spitballing here but you could do something like depending on what the week of the year is, you could set the replace value and the replaced-with value relative to that.

For example, if the current week of the year is 30 and you need to replace all period id's of 50 with 65, then do something like: if the period id = (Date.WeekOfYear([date]) + 20) replace it with (Date.WeekOfYear([date]) + 35). Then the next week, the week of year would increase by 1, therefor increasing the period id and replacement value also by 1. Just incorporate that into the function you already have.

 

Edit: looks like the other person said the same thing as me but a few minutes sooner and with the actual formula haha.

AlB
Community Champion
Community Champion

Hi @Anonymous 

If this week, week number 41 is the one you take as base, then:

 

= Table.ReplaceValue(#"Replaced Value2",each [PeriodId], each if [PeriodId]=65+Date.WeekOfYear(DateTime.LocalNow())-41 and [ApplicationId]>=34 and [ApplicationId]<=36 then 122+Date.WeekOfYear(DateTime.LocalNow())-41 else [PeriodId],Replacer.ReplaceValue,{"PeriodId"})

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

Worked perfect auto-updating this week. Thanks AIB!

Anonymous
Not applicable

Thanks AIB. I just plugged it in and so far looks beautiful. The real test will be the data refresh next week.

 

Being that I plugged it in using this week as the base, am I correct in assuming that next week the formula will find the next week's value ( which increases by 1) and replace it accordingly?

AlB
Community Champion
Community Champion

@Anonymous 

Correct

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
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.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

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