I have a problem in DAX when displaying a metric in an area chart. The goal is to represent unique users who have performed a number of actions equal to or greater than [n_veces] during the last [meses] consecutively.
TotalUsuariosRecurrentes =
VAR SELECTOR = IF([Recurrencia numerico] = 365,12,[meses])
VAR SELECTOR_veces = [n_veces]
VAR hoy = TODAY()
VAR FechaIni = EDATE(hoy,SELECTOR * -1)
VAR FechaFin = hoy
VAR ResumenUsuarios =
SUMMARIZE(
FILTER(
Tabla,
Tabla[EndOfMonth] >= FechaIni && Tabla[EndOfMonth] <= FechaFin
),
Tabla[UserId],
Tabla[EndOfMonth],
"SumaVisitas", SUM(Tabla[N_VISITAS])
)
VAR UsuariosRecurrentes =
SELECTCOLUMNS(
FILTER(
SUMMARIZE(
ResumenUsuarios,
[UserId],
"MesesConVisitas", COUNTROWS(
FILTER(
ResumenUsuarios,
[UserId] = EARLIER([UserId]) &&
[SumaVisitas] >= SELECTOR_veces
)
)
),
[MesesConVisitas] >= SELECTOR
),
"UserId", [UserId]
)
RETURN
CALCULATE(
DISTINCTCOUNT(Tabla[UserId]),
FILTER(
Tabla,
Tabla[UserId] IN UsuariosRecurrentes &&
Tabla[EndOfMonth] >= FechaIni && Tabla[EndOfMonth] <= FechaFin
)
)
To help you understand the logic I am using in the metric I will explain the following parameters:
1.[n_veces] = number of actions (int)
2.[meses] = number of months (int)
3.[Recurrencia numerico] = if recurrence slicer has de value “Mensual” selected, then 30, else 365 (int)
Those parameters filters the table shown below and should also filter the area visualization located just below the table.
https://i.sstatic.net/Tp51qgoJ.png
This is the how the data looks like:
https://i.sstatic.net/GPIFdYjQ.png
The problem is that, when I select a number of month ([meses]) greater than 1, it stop showing the visualization when it should show, in this specific case the last 3 months (X axis) with just 1 user (Y axis) as is the only one who have done at least 2 actions each month during the last 3 months:
EndOfMonth | Users |
---|---|
30/07/2024 | 1 |
30/06/2024 | 1 |
31/05/2024 | 1 |
I expect to be able to show an evolution on this metric having the date field on X axis, now it can only be displayed on a KPI visualization.
As the data have more detail that the required for the metric (EndOfMonth,UserId,WorkspaceId,ReportId,Visits), I have tried to do a summarized table on a variable to calculate the users with the conditions selected (UsuariosRecurrentes) and then tried to insert that list of users on the calculate after the return statement.
Any help on this?
Thanks a lot!
OscarCamean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.