Forum Discussion

beckyconning's avatar
beckyconning
Icon for Helper I rankHelper I
6 years ago
Solved

Subsequent GROUP BYs in Power BI

I'm trying to figure out which analysis tools to ask my team to use. As an example task I'm trying to work out from a FDA dataset what affects different combinations of drugs may have. In SQL I...
  • beckyconning's avatar
    beckyconning
    6 years ago

    I was a little confused. You posted some code above but thats 414 characters whereas the original SQL is 299 characters.

    Also with minor changes the SQL works in every SQL dialect whereas the code you posted appears to be specific to Power BI.

    I thought the point of tools like Power BI was to allow business users to analyse data whilst writing less code than would be required without Power BI and that this was at odds with this.

    It seems that Power BI goes most of the way in this case though.

    When I right click on my table and click "Edit query"

    And I right click a blank value in the "Active substance" column

    And click "Text Filters"
    And click "Does not equal"
    And I click "Group by"

    And I click "Advanced"

    And I provide "Report id" as the first grouping
    And I click "Add grouping"
    And I provide "Reaction" as the second grouping

    And I provide "Active substances" as the "New column name"
    And I provide "Min" as the "Operation"
    And I provide "Active substance" as the "Column"

    And I click "OK"
    And I click "View"

    And I click "Advanced editor"
    And I replace `List.Min([Active substance])` with `Text.Combine(List.Distinct([Active substance]), ", ")`
    And I click "Done"

    And I click "Group by"

    And I click "Advanced"

    And I provide "Active substances" as the first grouping
    And I click "Add grouping"

    And I provide "Reaction" as the second grouping
    And I provide "Count" as the "New column name"
    And I provide "Count Rows" as the "Operation"

    And I click "OK"

    And I sort the table by "Count" descending

    And I click "Home"
    And I click "Close & Apply"
    And I click "Table"

    And I click the checkbox next to "Active substances"
    And I click the checkbox next to "Reaction"
    And I click the checkbox next to "Count"

    Then I see the results I expected.

     

    It would be nice to be able to do the `List.Distinct` and the `Text.Combine` from the UI rather than the code editor but clearly 53 characters is an improvement over 299.