I have a text column and would like to convert it to Proper. Is there a way to do it using DAX only? I dont want to use inbuilt powerbi functions
Proper case is any text that is written with each of the first letters of every word being capitalized. For example, "This Is An Example Of Proper Case." is an example of sentence in proper case. Tip. Proper case should not be confused with Title case, which is most of the words being capitalized.
for example
text_column
apple bat
cab
Run Code Online (Sandbox Code Playgroud)
should change to
Text_column
Apple Bat
Cab
Run Code Online (Sandbox Code Playgroud)
以下是如何使用 DAX 将文本字符串转换为正确的大小写。从示例表开始:
Table =
DATATABLE(
"ID" , INTEGER ,
"Text" , STRING ,
{
{ 1 , "The quick brown fox jumps over the lazy dog" } ,
{ 2 , "Happy Birthday" }
}
)
Run Code Online (Sandbox Code Playgroud)
然后将此 DAX 代码添加为计算列:
Text Proper =
VAR SplitByCharacter = " "
var var_text = 'Table'[Text]
VAR Table0 =
ADDCOLUMNS (
GENERATE (
CALCULATETABLE( 'Table', 'Table'[Text] = var_text ), // we shrink table to current row only
VAR TokenCount =
PATHLENGTH ( SUBSTITUTE ( 'Table'[Text], SplitByCharacter, "|" ) )
RETURN
GENERATESERIES ( 1, TokenCount )
),
//"Word", PATHITEM ( SUBSTITUTE ( 'Table'[Text], SplitByCharacter, "|" ), [Value] ),
//"cnt", PATHLENGTH ( SUBSTITUTE ( 'Table'[Text], SplitByCharacter, "|" ) ),
"Proper",
var word = PATHITEM ( SUBSTITUTE ( 'Table'[Text], SplitByCharacter, "|" ), [Value] )
var word_Propper = UPPER( LEFT( word, 1 ) ) & LOWER( RIGHT( word, LEN( word) - 1 ) )
return
word_Propper
)
RETURN
CONCATENATEX( Table0, [Proper], " " )
Run Code Online (Sandbox Code Playgroud)
我受 Phil Seamark 文章的启发编写了这段代码:
https://dax.tips/2019/07/05/dax-pivot-text-into-a-list-of-words/
| 归档时间: |
|
| 查看次数: |
16619 次 |
| 最近记录: |