【问题标题】:Using CASE or IF Statement in Power BI在 Power BI 中使用 CASE 或 IF 语句
【发布时间】:2023-01-06 23:17:02
【问题描述】:

我想让一定比例的白人分开,而其余种族将是目前正在从事的项目中的有色人种。请帮助我如何使用 CASE 或 IF 语句编写 DAX。

我使用了 SWITCH,它给出了错误

Race_Ethnicity = 
SWITCH(TRUE(),
    'Contact'[race_and_ethnicity] = "White or European", "White or European",
    'Contact'[race_and_ethnicity] = "Black or African", "Black or African",
    'Contact'[race_and_ethnicity] = "Hispanic or Latinx", "Hispanic or Latinx",
    'Contact'[race_and_ethnicity] = "Prefer not to answer", "Prefer not to answer",
    'Contact'[race_and_ethnicity] = "South Asian", "South Asian",
    'Contact'[race_and_ethnicity] = "East Asian", "East Asian",
    'Contact'[race_and_ethnicity] = "Middle Eastern", "Middle Eastern",
    'Contact'[race_and_ethnicity] = "Southeast Asian", "Southeast Asian",
    'Contact'[race_and_ethnicity] = "Pacific Islander", "Pacific Islander",
    'Contact'[race_and_ethnicity] = "Indigenous","Indigenous",
    'Contact'[race_and_ethnicity] = "Other, please specify:", "Other, please specify:",
    'Contact'[race_and_ethnicity] = ".*(;).*", "Mixed Race or Ethnicity",
)

我希望有白人或欧洲人的百分比以及有色人种的百分比

【问题讨论】:

    标签: if-statement powerbi case dax


    【解决方案1】:

    这里有两个措施。一个是白人/欧洲人的百分比:

    WOE % = 
    VAR _count = 
        CALCULATE ( 
            COUNTROWS ( 'Contact' ) , 
            'Contact'[race_and_ethnicity] = "White or European"
        )
    RETURN
        DIVIDE ( 
            _count , 
            COUNTROWS ( 'Contact' )
        )
    

    一个相反:

    POC % = 
    VAR _count = 
        CALCULATE ( 
            COUNTROWS ( 'Contact' ) , 
            'Contact'[race_and_ethnicity] <> "White or European"
        )
    RETURN
        DIVIDE ( 
            _count , 
            COUNTROWS ( 'Contact' )
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多