DAX,Power BI-连接字符串

时间:2019-02-13 17:19:16

标签: powerbi dax

有人知道DAX可以连接图像中示例的行吗?我想制定一项新的措施,将所有国家融合在一起,但要总结出重复的国家。 BR + BRA是巴西。

Example here

我可以在DAX中将这些国家的值加起来,这将返回数字,但是我对字符串特别感兴趣。例如“如果在BR和BRA国家,则在巴西,如果在CH和CHI国家,则在智利”。

谢谢!

3 个答案:

答案 0 :(得分:1)

创建一个统一国家/地区的计算列。

# mock your data
$list1 = @(
[pscustomobject]@{Name='YY'},
[pscustomobject]@{Address='ABC street'},
[pscustomobject]@{City='Seattle'},
[pscustomobject]@{Zip='01256'},
[pscustomobject]@{Name='XYZ'},
[pscustomobject]@{Address='XYZ street'},
[pscustomobject]@{City='XYZ'},
[pscustomobject]@{Zip='45456'},
[pscustomobject]@{Name='Mike'},
[pscustomobject]@{Address='1256 Street'},
[pscustomobject]@{City='New York'},
[pscustomobject]@{Zip='78965'}
)

# mock your data
$list2 = @(
@{Name='YY'},
@{Address='ABC street'},
@{City='Seattle'},
@{Zip='01256'},
@{Name='XYZ'},
@{Address='XYZ street'},
@{City='XYZ'},
@{Zip='45456'},
@{Name='Mike'},
@{Address='1256 Street'},
@{City='New York'},
@{Zip='78965'}
)

# debuggng...
#$list1
#$list1.GetType()
#$list1[0].GetType()

#$list2
#$list2.GetType()
#$list2[0].GetType()

# seems your data looks like list1

$data = @()
$entry = [ordered]@{}

# transform the data into separate objects based on the field you want
foreach ($item in $list)
{
    if ($item.Name) {$entry.Name = $item.Name}
    elseif ($item.Address) {$entry.Address = $item.Address}
    elseif ($item.City) {$entry.City = $item.City}
    elseif ($item.Zip) {$entry.Zip = $item.Zip; $data += $entry; $entry = [ordered]@{}}
}

# data transformed now into an array of hashtables
# there are a few says to save as csv, one is to just roll your own rather
# than GetEnumerator(), etc.

$out = @()
$out += $data[0].Keys -join ', '
$out += $data | % {
    #$_['Name']+','+$_['Address']+','+$_['City']+','+$_['Zip']
    # or
    #$_.Name+','+$_.Address+','+$_.City+','+$_.Zip
    # or 
    $_.Name,$_.Address,$_.City,$_.Zip -join ', '

}

$out

# save $out to a file, uncomment to use after editing path
#$out | Out-File -FilePath 'c:\mycsvfile.csv'

然后,除了all_countries = SWITCH( TRUE(); 'panelCmd'[country] IN { "BR", "BRA" }; "Brasil"; 'panelCmd'[country] IN { "CH", "CHI" }; "Chile"; 'panelCmd'[country] IN { "ES", "ESP" }; "Spain"; <...et cetera...> 'panelCmd'[country] ) 之外,还可以在表中使用该列来代替/。


country的引用:The Diabolical Genius of “SWITCH TRUE”

答案 1 :(得分:0)

您的意思是一种将多个字符串连接成单个逗号分隔的字符串的措施吗? 如果是这样,您可能要使用CONCATENATEX迭代器。更具体地说,在Power BI Desktop中,可以使用“快速测量”选项创建一个测量,然后选择底部的“连接...”选项。这将为您提供执行此操作的代码段,以及一个良好的起点。

答案 2 :(得分:0)

使用&连接字符串

例如:

“ String1”&“ String2”&“ String3” => String1 String2 String3

Subheading = "for events that occured up to "& FORMAT(TODAY(),"DD") & "th  " & FORMAT(TODAY(),"MMMM") & "

结果:发生在12月16日之前的事件

enter image description here