Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jaylsonphb
Regular Visitor

DAX countrows Time inteligence

Colegas, na tabela "fREGISTROS" necessito contar o número de linhas de "Id", desde que: a "DataMovimento" de cada "Id" seja dia útil e seja de dois dias atrás em relação à data de hoje (data em que o relatório é atualizado). As tabelas "fREGISTROS" e "dCALENDARIO" estão relacionadas corretamente por "DataMovimento" e "Data". Tentei algumas DAX de inteligência temporal com alguns filtros, mas sem sucesso.

Poderiam me auxiliar em uma solução.

Muito obrigado desde já.

fREGISTROS

jaylsonphb_0-1717351461904.png

 

dCALENDARIO

jaylsonphb_3-1717350046576.png

 

 

1 ACCEPTED SOLUTION

Realmente como você observou, fiz as devidas correções e pude ver as linhas sendo contadas.

Obrigado novamente.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi, @jaylsonphb 

In order to solve your current problem, you need to create a new calculation column in your date table to determine whether the current date is a working day, if it returns 1, otherwise 0. To calculate this column, you need to have the weekday column in your date table. Here's an example of a working day from Monday to Friday:

vjianpengmsft_0-1717381401593.png

ISWorkingday = IF([Weekday]<=5,1,0)

vjianpengmsft_1-1717381452844.png

The first variable is to filter out the days in the calendar table that are weekdays. This will return a date column. The second variable is to use DayDiff to calculate the number of days from today to the date corresponding to the current ID. Finally, if is used to determine whether IsOverTwoDays is greater than 2, then count the ID column. Before counting, use the filter to filter out the rows that correspond to the date corresponding to the current ID as a working day. Finally, count the ID column of the table that comes out of the filter.

countID = 
VAR _workingday = SELECTCOLUMNS(FILTER('Table','Table'[ISWorkingday]=1),'Table'[Date])
VAR IsOverTwoDays = DATEDIFF(SELECTEDVALUE(fREGISTROS[DataMovimento]),TODAY(),DAY)
RETURN IF(IsOverTwoDays>=2,COUNTAX(FILTER(ALLSELECTED('fREGISTROS'),'fREGISTROS'[Id]<=SELECTEDVALUE(fREGISTROS[Id])&&'fREGISTROS'[DataMovimento] IN _workingday),'fREGISTROS'[Id]))

Here are the results:

vjianpengmsft_2-1717382075566.png

In your example data, 1/15/2024, 1/16/2024, 1/17/2024, and 1/18/2024 are all working days, as shown in the following figure:

vjianpengmsft_3-1717382480951.png

If your working day is not Monday to Friday, you need to adjust the calculation column of ISWorkingday appropriately.

I've provided the PBIX file used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Aprecio sua resposta em esclarecer a necessidade de ter colunas calculadas e ter variáveis na DAX, entretanto devido a outros motivos não pude subir com sucesso o arquivo que gostaria de trabalhar (desculpe por isso), mas ele está disponível aqui: (excluído)

Tentei replicar sua ajuda/medida na tabela onde irei trabalhar que é "fProdutividade" relacionando ela com a tabela tipo calendário "CALENDARIOPQ", porém a DAX não conseguiu contar as linhas. (Destaque abaixo)

jaylsonphb_0-1717468196682.png

 

 

Meu obejtivo é: contar o número de linhas de "Id_PREA", desde que: a "DataTratamento" de cada "Id_PREA" seja dia útil e também seja de dois dias atrás em relação à data de hoje (data em que o relatório é atualizado). 

Observe que a tabela "CALENDARIOPQ" vem do Power Query (para poder incluir uma lista de feriados para melhor atender à minha demanda).
Novamente muito obrigado pela sua ajuda e esclarecimentos.

Anonymous
Not applicable

Hi, @jaylsonphb 

Thank you very much for your reply. The reason why this measure doesn't work is because the calendar table has the hours, minutes, and seconds after the date are all 12:00:00, as shown in the following image:

vjianpengmsft_0-1717468726620.png

This doesn't match the hours, minutes, and seconds after your actual date column, so it's shown empty:

vjianpengmsft_1-1717468796195.png

So we can change the original DAX expression like this:

countID = 
VAR vDiaUtil = SELECTCOLUMNS(FILTER('CALENDARIOPQ','CALENDARIOPQ'[DiaUtil]=1),'CALENDARIOPQ'[Data])
VAR vLegado = DATEDIFF(SELECTEDVALUE(fProdutividade[DataTratamento]),TODAY(),DAY)
RETURN IF(vLegado>=2,COUNTAX(FILTER(ALLSELECTED(fProdutividade),'fProdutividade'[Id_PREA]<=SELECTEDVALUE(fProdutividade[Id_PREA])&&DATEVALUE(FORMAT('fProdutividade'[DataTratamento],"MM/DD/YYYY")) IN vDiaUtil),'fProdutividade'[Id_PREA]))

In this DAX expression, I first use the format function to convert your date column to MM/DD/YYYY format. Since the format function returns a text date, I used the datevalue function. The main purpose of this function is to change the date of the text type to the date type, so that it can be compared with the vDiaUtil.

vjianpengmsft_2-1717469035006.png

The results are as follows:

vjianpengmsft_3-1717469072667.png

 

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Realmente como você observou, fiz as devidas correções e pude ver as linhas sendo contadas.

Obrigado novamente.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.