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
Anonymous
Not applicable

¿Cómo puedo crear una medida que calcula la suma acumulada de solo determinadas filas?

Tengo algunos datos mensuales de gastos con múltiples observaciones de gastos registradas al mes. Se ve así:

year	month	expenditures
2020	1	4838
2020	1	3844
2020	2	1784
2020	2	2796
2020	3	2660
2020	3	3707
2020	4	4769
2020	4	1386
2020	5	4764
2020	5	4041
2020	6	1601
2020	6	3549
2020	7	1699
2020	7	2442
2020	8	1665
2020	8	2082
2020	9	2977
2020	9	3676
2020	10	1406
2020	10	3245
2020	11	4433
2020	11	3083
2020	12	2009
2020	12	2376
2021	1	2074
2021	1	3032
2021	2	4397
2021	2	3692
2021	3	1873
2021	3	2330
2021	4	1129
2021	4	4205
2021	5	1977
2021	5	3030
2021	6	4021
2021	6	1944
2021	7	1356
2021	7	3744
2021	8	2681
2021	8	3421
2021	9	0
2021	9	0
2021	10	0
2021	10	0
2021	11	0
2021	11	0
2021	12	0
2021	12	0

Quiero calcular una medida que me da la suma acumulada de los gastos por mes, restableciéndome cuando el año cambia. También quiero que esta medida no registre ningún valor durante meses que aún no hayan ocurrido (es decir, septiembre de 2021 en adelante). Por ejemplo, los gastos acumulados en febrero de 2020 deberían ser de 13.262, los gastos acumulados en diciembre de 2020 deberían ser de 70.382, los gastos acumulados en febrero de 2021 deberían ser de 13.195 y los gastos acumulados para septiembre de 2021 deberían ser un valor en blanco o falta.

¿Cómo podría hacer esto? Cualquier ayuda sería muy apreciada!

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hola @noahspencer ,

Cree una medida como se muestra a continuación:

Measure = IF(MAX('Table'[expenditures])<>0,SUMX(FILTER(ALL('Table'),'Table'[month]<=MAX('Table'[month])&&'Table'[year]=MAX('Table'[year])),'Table'[expenditures]),BLANK())

Y verás:

QQ图片20200914201132.png

Para el archivo .pbix relacionado, pls ver adjunto.

View solution in original post

5 REPLIES 5
v-kelly-msft
Community Support
Community Support

Hola @noahspencer ,

Cree una medida como se muestra a continuación:

Measure = IF(MAX('Table'[expenditures])<>0,SUMX(FILTER(ALL('Table'),'Table'[month]<=MAX('Table'[month])&&'Table'[year]=MAX('Table'[year])),'Table'[expenditures]),BLANK())

Y verás:

QQ图片20200914201132.png

Para el archivo .pbix relacionado, pls ver adjunto.

Anonymous
Not applicable

¡Muchas gracias! Esto funciona muy bien para mí.

Por curiosidad, ¿por qué necesita hacer la declaración lógica 'MAX(Expenditures) <> 0' en lugar de simplemente 'Gastos <>0'?

Greg_Deckler
Super User
Super User

@noahspencer quizás:

Column =
  SUMX(
    FILTER(
      'Table',
      [year] = EARLIER([year]) &&
        [month]<=EARLIER([month])
    ),
    [expenditures]
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Gracias por su respuesta! Eso funciona para calcular la suma acumulada por mes, pero no da valores que faltan/en blanco para los meses que aún no han ocurrido. ¿Tienes alguna idea ahí?

@noahspencer , Como nueva columna

Nueva columna Cumm á if(coalesce([expenditures],0)<>0, sumx(filter(Table,table[Year]-earlier(Table[Year]). table[Month]<-earlier(Table[Month])),[expenditures]),blank())

En caso de que necesite medida y prefiera tener fecha y unirse a ella con la tabla de fechas
fecha: fecha([año],[mes],1)

MTD - CALCULATE(SUM(Table[expenditures]),DATESMTD('Date'[Date]))

YTD - CALCULATE(SUM(Table[gastos]),DATESYTD('Date'[Date],"12/31"))

Medida final: if([MTD]<>0,[YTD],blank())

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 Kudoed Authors