Tenho uma tabela chamada Query 2
no Power BI.
id_do_registro | site | data_de_início | atividade | data_final | duração | contagem_total |
---|---|---|---|---|---|---|
10 | 1 | 24/09/2022 | beisebol | 01/10/2022 | 1 | 1 |
10 | 1 | 10/11/2022 | beisebol | 11/1/2022 | 1 | 2 |
10 | 1 | 24/09/2022 | basquetebol | 11/1/2022 | 3 | 3 |
10 | 1 | 01/10/2022 | basquetebol | 11/1/2022 | 3 | |
10 | 1 | 10/11/2022 | basquetebol | 11/1/2022 | 3 | |
10 | 1 | 10/11/2022 | futebol | 12/12/2022 | 2 | 4 |
10 | 1 | 11/1/2022 | futebol | 12/12/2022 | 2 | |
10 | 1 | 11/1/2022 | futebol | 12/12/2022 | 1 | 5 |
A coluna total_count
é o que estou tentando realizar, não é uma coluna real nos dados e precisará ser calculada. Ela é calculada com base na combinação de record_id, activity e end_date. Quando uma dessas três colunas muda, ela deve contar como uma. Se esses valores ainda forem os mesmos na próxima linha, a contagem não deve mudar e essa linha permanecer em branco, mas se um dos valores na próxima linha mudar, a contagem deve aumentar. Eu tentei o seguinte código e está próximo:
Total_Count =
VAR CurrentRow =
'Query2'[record_id] & "-" & 'Query2'[Activity] & "-" & 'Query2'[end_date] & "-" & 'Query2'[duration]
VAR PreviousRows =
FILTER(
'Query2',
'Query2'[record_id] & "-" & 'Query2'[Activity] & "-" & 'Query2'[end_date] & "-" & 'Query2'[duration] < CurrentRow
)
RETURN
IF(
RANKX(
FILTER(
'Query2',
'Query2'[record_id] = EARLIER('Query2'[record_id]) &&
'Query2'[Activity] = EARLIER('Query2'[Activity]) &&
'Query2'[end_date] = EARLIER('Query2'[end_date]) &&
'Query2'[duration] = EARLIER('Query2'[duration])
),
'Query2'[start_date],
,
ASC,
DENSE
) = 1,
COUNTROWS(PreviousRows) + 1,
BLANK()
)
A contagem dá errado depois da primeira repetição, onde eu tenho 4 no meu total_count
, eu tenho 6.
Experimente esta variação: ela conta combinações únicas anteriores em vez de linhas: