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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
apenaranda
Post Patron
Post Patron

Data from a table (count and sum)

Hello, I have the following table as data

 

NoFechaCod. User
101/01/20241
201/01/20241
303/01/20242
404/01/20243
505/01/20243
601/01/20242
707/01/20244
808/01/20246
908/01/20247
1008/01/20241
1111/01/20241
1212/01/20243
1329/01/20243
1430/01/20244
1531/01/20243

 

I need to get a series of data:
1. For each user, how many registrations are there per day?
Example: User 1 has 4 records
2. For each day, know how many different users have records
Example: for the day 1/1/2024 there are 3 records
For 01/08/2024 there are 3 records
3. From data 2, add the amount
Example: following the previous example, the sum would be 3 + 3 = 6
4. count the days when there are records
Example: according to the previous example, the result would be 2 days.

 

thank you.

12 REPLIES 12
Syndicate_Admin
Administrator
Administrator

Hola @Syndicate_Admin ,

Gracias @ChiragGarg2512 por sus respuestas y permítanme darles otra idea:


Para ello, cree una medida.

Measure =
CALCULATE(COUNT('Table'[No]),FILTER(ALL('Table'),'Table'[Cod. User] = MAX('Table'[Cod. User]))))

Measure 2 =
CALCULATE(COUNT('Table'[No]),FILTER(ALL('Table'),'Table'[Date] = MAX('Table'[Date]))))

Measure 3 =
CALCULATE(COUNT('Table'[No]),FILTER(ALL('Table'),'Table'[Measure 2] > 1))

Measure 4 =
CALCULATE(DISTINCTCOUNT('Table'[Date]),FILTER(ALL('Table'),'Table'[Measure 2] > 1))

vkaiyuemsft_0-1714012546179.png

Si su período actual no se refiere a esto, por favor aclárelo en una respuesta de seguimiento.

Saludos

Clara Gong

Si esta publicación ayuda, considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

I think we are not understanding each other and I think I also got confused in one of the answers...

apenaranda_0-1714023624907.png

 


Forget option 1 and 2 because I already have them, I attached a screenshot of where you can see them.
Now I am missing 3 and 4, if you look at the screenshot, in the table below, the total says 6, it is not correct, what I want is the sum that according to the screenshot should be 14 if I have not counted wrong.

On the other hand, apart from the total sum, I want the count of days, according to the attached table it should be 11 (these are the days with at least 1 record)

I don't know if the captures have made it better understood.
Thank you.

Hola @Syndicate_Admin ,

Es una situación relativamente común que la medida en el total sea incorrecta, la medida sigue el contexto de la fila "Total" y se calcula en ese contexto. Por lo tanto, las medidas utilizadas en las columnas de visualizaciones de tabla pueden tener valores inesperados en la columna Total.


Puede utilizar las siguientes medidas, utilizar la función IF() + ISINSCOPE() para determinar el nivel de datos y, a continuación, realizar diferentes cálculos en función del nivel.

La medida 2 se puede modificar para:

Measure 2 =
VAR _count = CALCULATE(COUNT('Table'[No]),FILTER(ALL('Table'),'Table'[Date] = MAX('Table'[Date])))
VAR _total_count = COUNT('Table'[No])
RETURN
IF(ISINSCOPE('Table'[Date]),_count,_total_count)

Si desea calcular el número de días con al menos 1 registro, puede modificar el compás 4 para:

Measure 4 =
CALCULATE(DISTINCTCOUNT('Table'[Date]),FILTER(ALL('Table'),'Table'[Measure 2] >= 1))

vkaiyuemsft_0-1714119691384.png

Si su período actual no se refiere a esto, por favor aclárelo en una respuesta de seguimiento.

Saludos

Clara Gong

Si esta publicación ayuda, considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Could you briefly explain Measure 2 to me, I don't really understand what they do.
Anyway, I see that it doesn't add up, Measure 2 says that on 01/01/2024 there are three different users when there are only two (user 1 and 2)
Measure 4 is already clear to me and it is correct.

Hola @Syndicate_Admin ,

Modifiqué la medida 2 y agregué algunos comentarios más.

Measure 2 =
VAR _count = CALCULATE(DISTINCTCOUNT('Table'[Cod. User]),FILTER(ALL('Table'),'Table'[Date] = MAX('Table'[Date]))) //Counts the different user codes for the current date
VAR _table = SUMMARIZE('Table','Table'[Date],'Table'[Cod. User]) // Create virtual table to get table with unique date and user code values
VAR _total_count = COUNTROWS(_table) // Count the number of rows in the virtual table
RETURN
IF(ISINSCOPE('Table'[Date]),_count,_total_count) // Display different data in layers, date layer and total layer display different counts

vkaiyuemsft_0-1714378317143.png

Si su período actual no se refiere a esto, por favor aclárelo en una respuesta de seguimiento.

Saludos

Clara Gong

Si esta publicación ayuda, considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.


Puede encontrar más información sobre la función ISINSCOPE en la documentación: Función ISINSCOPE (DAX) - DAX | Microsoft Learn.

Sorry, I don't understand the VAR _count part when you add the
FILTER(ALL('Table'),'Table'[Date] = MAX('Table'[Date]))

Hola @Syndicate_Admin ,

La columna calculada puede obtener directamente el valor actual, pero meausre requiere una función agregada como max() para obtener el valor actual. Por lo tanto, al realizar operaciones de cálculo de grupo, measure debe usar la función max para obtener el valor actual y solo se calcularán los mismos valores juntos.

Saludos

Clara Gong

Si esta publicación ayuda, considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

In my real case, I have the table and the date column is related to a date table.
So should I put this last part like this?
FILTER(ALL(Cab_act_almacen_reg_sql),Cab_act_almacen_reg_sql[Registering Date] = MAX(Fechas[Date]))

Table Cab_act_almacen_reg_sql would be the one for records
Dates[Date] would be the dates related to Cab_act_almacen_reg_sql[Registering Date]

If I do as I attached, the total does not do it correctly, yes by rows but the total does as before.

Here is all my measure:

 

Measura 2 = 
VAR _count = CALCULATE(DISTINCTCOUNT(Cab_act_almacen_reg_sql[Cod_ operario almacen]),FILTER(ALL(Cab_act_almacen_reg_sql),Cab_act_almacen_reg_sql[Registering Date] = MAX(Fechas[Date]))) //Counts the different user codes for the current date
VAR _table = SUMMARIZE(Cab_act_almacen_reg_sql,Cab_act_almacen_reg_sql[Cod_ operario almacen]) // Create virtual table to get table with unique date and user code values
VAR _total_count = COUNTROWS(_table) // Count the number of rows in the virtual table
RETURN
IF(ISINSCOPE(Fechas[Date]),_count,_total_count) // Display different data in layers, date layer and total layer display different counts

 

Thank you.

Syndicate_Admin
Administrator
Administrator

1) Medida = CALCULATE(COUNTROWS('Tabla'), REMOVEFILTERS('Tabla'[No], 'Tabla'[Fecha]))

2) Medida2 = CALCULATE(COUNTROWS('Table'), REMOVEFILTERS('Table'[No], 'Table'[Cód. Usuario]))
3) y 4) son un poco confusos

The measure in point 2 makes the sum of all the registrations for that day, but what I want is to know how many different users there are with registrations that day.

 

Let's explain it in another way to see if it can be understood better:
Point 3 is basically the sum of records
Point 4, of the entire month (in this example case it is January), how many days there are with at least 1 record, that is, of the 31 days that January has, how many of them there are any records.

3) Las filas de conteo simples deberían ser suficientes

4) Aplique CountRows en la tabla donde la fecha está entre el inicio y el final del mes.

2) I already get it, but would there be a way for me to also add up the total for every day?

Now it sets me for 1/1/2024 there are 2 users
For 2/1/2024 there are 3 users
I would only need the sum of all the days.
3) if correct, a count already adds up the records per day
4) I don't really understand what you mean.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors