首页 文章

计算列中出现的次数

提问于
浏览
2

我对不同群体的成员(例如第1组到第4组)进行了调查,了解他们是否同意或不同意某些内容 . 我正在尝试在Microsoft PowerBI Desktop中绘制这些响应 .

我加载了一个数据模型,在单个表中包含这些列:

Group    Question1   Question2
Group1   Agree       Agree
Group1   Disagree    Agree
Group4   Disagree    Disagree
Group3   Agree       Agree
Group2   Disagree    Agree
Group2   Agree       Disagree
Group4   Agree       Agree
Group1   Agree       Disagree

我想知道是否有DAX可以计算单词“同意”和“不同意”的出现次数,这样我就可以将它们作为堆积条形图上的值(每个问题一个图表):

Group1   Agree---------   Disagree----
Group2   Agree-------  Disagree-------
Group3   Agree----------  Disagree----
Group4   Agree------  Disagree--------

(为ASCII艺术道歉)

我尝试过使用COUNTA()函数,但它只是继续返回行数 . 我还尝试将问题列作为数据字段拖动,但它再次,只是使每个条的长度相同,因为它们都具有相同的总响应数 .

提前致谢 .

3 回答

  • 0

    您需要将表格取消 - 以获得如下结构:

    Group  |  Question  |  Answer
    Group1 |  Question1 |  Agree
    Group1 |  Question2 |  Disagree
    ...
    

    您的衡量标准如下所示:

    RowCount:= COUNTROWS(FactAnswer)
    
    AgreeCount:=
    CALCULATE(
        [RowCount]
        ,FactAnswer[Answer] = "Agree"
    )
    
    DisagreeCount:=
    CALCULATE(
        [RowCount]
        ,FactAnswer[Answer] = "Disagree"
    )
    
  • 0

    我们需要制定六项措施(明确和简化)

    1) Agree Q1 = CALCULATE(COUNTA(SO_table[Question1]),SO_table[Question1]="Agree")

    2) Agree Q2 = CALCULATE(COUNTA(SO_table[Question2]),SO_table[Question1]="Agree")

    3) Disagree Q1 = CALCULATE(COUNTA(SO_table[Question1]),SO_table[Question1]="Disagree")

    4) Disagree Q2 = CALCULATE(COUNTA(SO_table[Question2]),SO_table[Question1]="Disagree")

    5) Total Agree = Agree Q1 + Agree Q2

    6) Total Disagree = Disagree Q1 + Disagree Q2

    然后你可以使用Stacked bar并绘制 Total AgreeTotal Disagree

  • 2

    您可以使用以下DAX表达式为每个问题创建一个表:

    Table = SUMMARIZE('YourTable',YourTable[Group],"Agree",
    COUNTAX(FILTER('YourTable',YourTable[Question1]="Agree"),
    YuorTable[Question1]),"Disagree",
    COUNTAX(FILTER('YourTable',YourTable[Question1]="Disagree"),YourTable[Question1]))
    

    例:

    YourTable

    enter image description here

    对于Question1,您将获得下表:

    enter image description here

    获得表后,只需创建所需的图表即可 .

    如果这有用,请告诉我 .

相关问题