简体   繁体   English

Power BI 矩阵表中具有多种数据类型的列

[英]Column with multiple data types in Power BI Matrix Table

My issue is similar to this one Multiple data types in a Power BI matrix but I've got a bit of a different setup that's throwing everything off.我的问题类似于Power BI 矩阵中的多种数据类型,但我有一些不同的设置,这会让一切都失败。

What I'm trying to do is create a matrix table with several metrics that are categorized as Current (raw data values) and Prior (year over year percent growth/decline).我要做的是创建一个矩阵表,其中包含几个指标,这些指标被归类为当前(原始数据值)和先前(同比增长/下降百分比)。 I've created some dummy data in Excel to get the format the way I want it in PowerBI (see below):我在 Excel 中创建了一些虚拟数据,以在 PowerBI 中获得我想要的格式(见下文):

Desired Format所需格式

As you can see the Current values are coming in as integers and the Prior % numbers as percentages which is exactly what I want;如您所见,当前值以整数形式出现,而 Prior % 数字以百分比形式出现,这正是我想要的; however, I was able to accomplish this through a custom column with the following formula:但是,我能够通过使用以下公式的自定义列来完成此操作:

Revenue2 = IF(Scorecard2[Current_Prior] = "Current", FORMAT(FIXED(Scorecard2[Revenue],0), "$#,###"), FORMAT(Scorecard2[Revenue], "Percent"))

The problem is that the data comes from a SQL query and you can't use the FORMAT() function in DirectQuery.问题是数据来自 SQL 查询,您不能在 DirectQuery 中使用 FORMAT() function。 Is there a way I can have two different datatypes in the same column of data?有没有办法在同一列数据中拥有两种不同的数据类型? See below for how the SQL data comes into PowerBI (I can change this if need be):有关 SQL 数据如何进入 PowerBI 的信息,请参见下文(如果需要,我可以更改此设置):

SQL SQL

Create 2 separate measures, one for the Current second for Prior, and format these measures.创建 2 个单独的度量,一个用于当前,第二个用于先前,并格式化这些度量。 Probably you can also use a case in SQL query to format your data to bring it as STRING.可能您还可以在 SQL 查询中使用一个案例来格式化您的数据以将其作为字符串。

What I wound up doing was reformatting the SQL code to look like this:我最终要做的是重新格式化 SQL 代码,如下所示:

Solution解决方案

That way Current/Prior are have two separate values and the "metric" is categorical.这样当前/之前有两个单独的值,“指标”是分类的。

I got the idea from this post: Simple way to transpose columns and rows in SQL?我从这篇文章中得到了这个想法: 在 SQL 中转置列和行的简单方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM