Search code examples
powerbidax

Powebi: new table based on filtered data from another table


I need to create new table based on data in another table im powerbi. Output table should contain columns: Name, Month, Number of Items - total count of items equal to true, Numer of Items2 - total count of items2 equal to true

Sample base table:

| Name | Month | Items | Items2 |
| ---- | ----- |------ | ------ |
| Ala  | 01    | true  | false  |
| Ala  | 01    | true  | false  |
| Ala  | 02    | true  | false  |
| Ala  | 01    | false | true   |
| Ala  | 02    | false | true   |
| Ola  | 01    | false | false  |
| Ola  | 02    | true  | true   |
| Ola  | 01    | false | true   |

Output table should look like this

| Name | Month |Nb of Items | Nb of Items2 |
| ---- | ----- |------------| ------------ |
| Ala  | 01    | 2          | 1            |
| Ala  | 02    | 1          | 1            |
| Ola  | 01    | 0          | 1            |
| Ola  | 02    | 1          | 1            |

Solution

  • Use SUMMARIZE to group by Name and Month. Then CALCULATE will change the context of the calculation to count the number of rows for Items = TRUE() and Items2 = TRUE() separately :

    NewTable = 
    SUMMARIZE(
        MyTable,
        MyTable[Name],
        MyTable[Month],
        "Nb of Items", CALCULATE(IF(COUNTROWS(MyTable) == BLANK() ,0,COUNTROWS(MyTable)) , MyTable[Item] = TRUE()),
        "Nb of Items2", CALCULATE(IF(COUNTROWS(MyTable) == BLANK() ,0,COUNTROWS(MyTable)) , MyTable[Item2] = TRUE())
    )
    

    enter image description here