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
Syndicate_Admin
Administrator
Administrator

Cálculo del mes anterior

Hola

Tengo una fórmula DAX que no funciona para calcular las reuniones del mes anterior.

Está en blanco, por lo que parte de la fórmula no funciona y espero ayuda con la sintaxis, ya que he probado algunas cosas y nada funciona.

Esto es lo que tengo:

Previous Month = 
VAR CurrentYear = YEAR(TODAY())
VAR CurrentMonth = MONTH(TODAY())
  
  RETURN
  IF ( [ShowValueForDates],
    CALCULATE (
        [Meetings Count],
             YEAR('Dates'[Date]) = CurrentYear &&
             MONTH('Dates'[Date]) = CurrentMonth-1 ) )
7 REPLIES 7
Syndicate_Admin
Administrator
Administrator

Hola @JemmaD

Para su pregunta, aquí está el método que proporcioné:

Aquí hay algunos datos ficticios

"Mesa"

vnuocmsft_0-1705572938826.png

Cree una medida.

meeting count = 
var last_month =  MONTH(EOMONTH(TODAY(),-1))

RETURN 
    CALCULATE(
        SUM('Table'[Meetings Count]), 
        FILTER(
            ALL('Table'), 
            MONTH('Table'[date]) = last_month
        )
    )

Aquí está el resultado

vnuocmsft_2-1705573059819.png

vnuocmsft_3-1705573090197.png

Saludos

Nono Chen

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

Syndicate_Admin
Administrator
Administrator

La razón por la que no funcionará es porque se está refiriendo al mes cero del año 2024. (CurrentYear=2024, CurrentMonth=1, CurrentMonth-1=0).
¿Es mejor usar la función ANTERIORMES? https://learn.microsoft.com/cs-cz/dax/previousmonth-function-dax

Se agradecen las felicitaciones y la marca como solución.

¡Intenté usar la función PreviousMonth y tampoco funcionaba! ¿Podrías ayudarme con algo de sintaxis? ¡Mi DAX no es el mejor!

Reuniones del último mes = CALCULATE ( [Recuento de reuniones], PREVIOUSMONTH('Fechas'[Fecha]))

@zenisekd Sí, eso funciona, pero solo si tengo un año filtrado en el informe.

Quiero que funcione sabiendo cuál es el año actual y que calcule el mes anterior por sí mismo.

Esto es lo que tengo pero no funciona:

Previous Month = 
CALCULATE (
  [Meetings Count],
  PREVIOUSMONTH('Dates'[Date] ) && YEAR(TODAY() ) ) )

En ese caso, me quedaría con @Daniel29195 solución. En el caso del mes anterior, debe especificar el año y el mes...

Pruebe esto:

Mes anterior =

var selectedyear = max ( date[year])

var selectedmonth = max(date[month])

var prev_year = switch( true(), selectedmonth = 1 , selectedyear - 1 , selectedyear )

var prev_month = cambiar ( true(), selectedmonth = 1 , 12 , selectedmonth -1 )

var resultado =

calcular ( [recuento de reuniones] ,

dimdate[año]= prev_year,

dimdatep[mes] = prev_month,

all(dimdate)
)

Resultado devuelto

Esto debería funcionar.
@JemmaD

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.