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
mterry
Helper V
Helper V

Performing calculations on text

I have a column containing a period, which represents a month and year, i.e. 201807 is July of 2018. The data is formatted as a text, and I have a step to create a date from that data: 

Date.FromText(Text.Range([Period],0,4) & "-" & Text.Range([Period],4,2) & "-01")

 

The issue I have is that for some lines, I need the date to actually be for the next month - so if a certain criteria is met, then 201807 should actually come through as August 2018. I'm not sure hwo to modify the above code so that I can add a "1" to the text value and perform the conversion. 

 

Below is a sample of the data and code (red portion doesn't work, gives you and idea of what I want to happen) that I'm trying to update. Because of other transformations that take place my preference would be to leave the period as text. 

PeriodSequenceDate
20180718047/1/2017
20180718047/1/2017
20180718058/1/2017
2018071804

7/1/2017

 

if [Period] = "201807" and ([Sequence] = "1805" or [Sequence] = "1806") then Date.FromText(Text.Range([Period],0,4) & "-" & Text.Range([Period]+1,4,2) & "-01") else Date.FromText(Text.Range([Period],0,4) & "-" & Text.Range([Period],4,2) & "-01")

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @mterry,

 

You can convert the text to numeric before caculating, then, change its data type back to Text.

if [Period] = "201807" and ([Sequence] = "1805" or [Sequence] = "1806") then Date.FromText(Text.From((Number.FromText(Text.Range([Period],0,4))-1)) & "-" & Text.Range([Period],4,2) & "-01") else Date.FromText(Text.Range([Period],0,4) & "-" & Text.Range([Period],4,2) & "-01")

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

1 REPLY 1
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @mterry,

 

You can convert the text to numeric before caculating, then, change its data type back to Text.

if [Period] = "201807" and ([Sequence] = "1805" or [Sequence] = "1806") then Date.FromText(Text.From((Number.FromText(Text.Range([Period],0,4))-1)) & "-" & Text.Range([Period],4,2) & "-01") else Date.FromText(Text.Range([Period],0,4) & "-" & Text.Range([Period],4,2) & "-01")

1.PNG

 

Best regards,

Yuliana Gu

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

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.