Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi,
I have columns year and month of type int
| YEAR | MONTH |
| 2021 | 9 |
| 2021 | 10 |
I would like to combine them into a new column which need to be of type int as well and should have a leading zero in front of the month. Example: 202109
Note that I cannot create a text column and then change the type to int because that would screw up the query folding.
Thanks!
Solved! Go to Solution.
@Quiny_Harl do you like to do this in server side or after you bring it over to PQ?
in PQ this is how you can do it
Number.From(Text.From([Year])&(if(Text.Length(Text.From([Month]))=1) then Text.PadStart(Text.From([Month]),2,"0") else Text.From([Month])))
@Quiny_Harl do you like to do this in server side or after you bring it over to PQ?
in PQ this is how you can do it
Number.From(Text.From([Year])&(if(Text.Length(Text.From([Month]))=1) then Text.PadStart(Text.From([Month]),2,"0") else Text.From([Month])))
Thank you for your help. Actually, I accepted your answer as solution but then I saw that this solution prevents the query folding. Also, the resulting column is of type "any" and not not of type int. So unfortunatelly I cannot use it.
@Quiny_Harl which RDBMS are you using? You can do this transformation on the server side and not to be worried about query folding at all. ARe you using a TSQL?
It's not possible to do it on the server side. Otherwise, life would have been much easier 🙂
@Quiny_Harl like I asked what is the RDBMS?
and if it is TSQL, it is absolutely possible
declare @t1 as table (year int, month int)
insert into @t1
select * from
(values(2021,9),(2021,10)) t(a,b)
select *
, CASE WHEN LEN(month)=1 then convert(bigint,convert(nvarchar,year)+'0'+ convert(nvarchar,month))
WHEN LEN(month)>1 then convert(bigint,convert(nvarchar,year)+ convert(nvarchar,month))
end as test
from @t1
Thank you for your suggestion but I don't have permission to edit the database.
@Quiny_Harl if it is TSQL, you don't need to have the database edit rights. This code will work on any table, any views. I created the table to demonstarte my point. Simply run the following portion
select *
, CASE WHEN LEN(month)=1 then convert(bigint,convert(nvarchar,year)+'0'+ convert(nvarchar,month))
WHEN LEN(month)>1 then convert(bigint,convert(nvarchar,year)+ convert(nvarchar,month))
end as test
from transactionTBL
Writing a query on the database does not need edit right. Please check with youur DBA. As long as you can query the table from databse (as you are doing it now), you will not have issues running this native query.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |