简体   繁体   English

Power BI Dax多个IF AND语句

[英]Power BI Dax Multiple IF AND Statements

I have a DAX query in Power BI - see below. 我在Power BI中有一个DAX查询-参见下文。 I have created a new column in the data and I want to Group AgeWhenFirstSold(Mo) into Age buckets. 我在数据中创建了一个新列,我想将AgeWhenFirstSold(Mo)分组到Age桶中。

The result I get from this query is 0-5 Months but the 6-11 Months doesn't show in the column 我从此查询中获得的结果是0-5个月,但6-11个月未显示在该列中

Group AgeWhenFirstSold(Mo)- 6 Months =
IF (
    AND ( Sheet1[AgeWhenFirstSold(Mo)] >= "0", Sheet1[AgeWhenFirstSold(Mo)] <= "5" ),
    "0 - 5 Months",
    IF (
        AND ( Sheet1[AgeWhenFirstSold(Mo)] > "5", Sheet1[AgeWhenFirstSold(Mo)] <= "11" ),
        "6 - 11 Months"
    )
)

I suspect your issue is that alphabetically "11" <= "5" 我怀疑您的问题是按字母顺序“ 11” <=“ 5”

Try using VALUE(<text>) "Converts a text string that represents a number to a number." 尝试使用VALUE(<text>) “将表示数字的文本字符串转换为数字。”

eg VALUE( Sheet1[AgeWhenFirstSold(Mo)] ) >= 0 例如VALUE( Sheet1[AgeWhenFirstSold(Mo)] ) >= 0

However you can also configure bins and groups to avoid having to extract them with DAX: 但是,您也可以配置bin和组,以避免必须使用DAX提取它们:

Right-click AgeWhenFirstSold(Mo) in the FIELDS section of Power BI Desktop and choose New Group: 右键单击Power BI Desktop的FIELDS部分中的AgeWhenFirstSold(Mo),然后选择“新建组”:

在此处输入图片说明

A dialog then allows you to configure your new group. 然后,将出现一个对话框,您可以配置新组。

An example: 一个例子:

在此处输入图片说明

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

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