简体   繁体   中英

Power BI: Count rows of a table based on a criteria of another table

I have a table resuming the list of apps by month and year like this:

Table 1  
App | Month | Year  
A   |  1    |  2019  
B   |  1    |  2019  
C   |  1    |  2019  
D   |  1    |  2019  
E   |  1    |  2019  
...  
etc  

And I have a table that contains the info of all the tickets of the company, including the App and the Month and Year, like this:

Table 2  
IDTicket | App | Month | Year  
44424    | B   | 1     | 2019  
44425    | D   | 1     | 2019  
44426    | B   | 1     | 2019  
44427    | A   | 1     | 2019  
44428    | E   | 1     | 2019  
...  
etc

I need to add to the Table 1, a column that count the amount of tickets of Table 2 according to each app, month and year, like this:

Table1  
App | Month | Year  | CountOfTickets  
A   |  1    |  2019 | 1  
B   |  1    |  2019 | 2  
C   |  1    |  2019 | 0  
D   |  1    |  2019 | 1  
E   |  1    |  2019 | 1  

Try something like this:

CountOfTickets =
CALCULATE (
    COUNT ( Table2[IDTicket] ),
    Table2[App]   = EARLIER ( Table1[App] ),
    Table2[Month] = EARLIER ( Table1[Month] ),
    Table2[Year]  = EARLIER ( Table1[Year] )
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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