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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Syndicate_Admin
Administrator
Administrator

Ayuda con la suma acumulada por mes año con un filtro de categoría

Hola

Soy un novato en Powerbi y quiero crear un gráfico de líneas que muestre un total acumulado desglosado por años pero el gráfico lo mostraría mensualmente, también me gustaría tener una opción de filtro que al seleccionarla solo me mostrara las cifras de esa categoría. Vea la tabla a continuación:

Fechacategoríabeneficio
01/01/20231966
07/01/20232825
10/01/20231413
05/02/20231468
05/02/20231692
07/03/20232404
14/03/20231341
14/05/20232391
19/05/20231300
19/05/20233323
19/05/20231503
20/06/20232322
20/06/20232441
17/07/20231930
19/07/20231237
02/09/20232368
10/10/20231793
11/11/20232349
13/11/20231756
12/12/20231932
24/12/20232692
01/01/20241273
07/01/20242849
10/01/20242770
05/02/20241898
05/02/20241104
07/03/20241450
14/03/20242339
14/05/20241207
19/05/20242703
19/05/20241405
19/05/20243502
20/06/20241580
20/06/20242352
17/07/20241552
19/07/20241624
02/09/20241493
10/10/20242398
11/11/20242299
13/11/20241407
12/12/20241698
24/12/20241911

Entonces, el gráfico mostraría los meses en la parte inferior, los montos a la izquierda y tendría una línea por año como suma acumulada, luego puedo filtrar por la categoría

Espero haber tenido algún sentido aquí.

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Hola @zuber85 ,

@Corey_M ¡Buena respuesta! Pero creo que te olvidas de calcular el total acumulado desglosado por años, solo calculas el total de cada mes de cada año.

Y @zuber85 Si no necesita que todos los meses se muestren en la parte inferior, puede usar la jerarquía de fechas que se incluye con Power BI Desktop directamente o usar DAX:

Month = MONTH('Table'[Date])

Y elijo agregar una nueva segmentación de tablas para filtrar por la categoría (Para eliminar algunos de los efectos en el filtrado, sugeriría agregar una nueva tabla) :

vjunyantmsft_0-1714616799327.png

vjunyantmsft_1-1714617001197.png

A continuación, utilice este DAX para crear una medida para calcular el valor Total acumulado desglosado por años:

cumulative total broken down by years = 
CALCULATE(
    SUM('Table'[profit]),
    ALL('Table'),
    YEAR('Table'[Date]) = YEAR(MAX('Table'[Date])) && MONTH('Table'[Date]) <= MONTH(MAX('Table'[Date])) && 'Table'[category] IN VALUES('Slicer'[category])
)

vjunyantmsft_2-1714617152804.png

vjunyantmsft_3-1714617166993.png

Y el resultado final es el siguiente:

vjunyantmsft_4-1714617191389.png

vjunyantmsft_5-1714617200168.png

vjunyantmsft_6-1714617210136.png

vjunyantmsft_7-1714617237120.png


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

@v-junyant-msft @Corey_M

Muchas gracias.

Como novato me tomó un poco de tiempo, pero lo logré.

Syndicate_Admin
Administrator
Administrator

Las tablas de fechas son un tema muy común en PowerBI y te ayudarán mucho aquí.

Aquí hay una tabla de ejemplo que puede ayudarlo a comenzar (https://chandoo.org/wp/power-query-calendar-table-best-method/ )

let
    Source = List.Dates(#date(2023,1,1),365, #duration(1,0,0,0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([Date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Month", "Month Name", each Date.MonthName([Date]), type text),
    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Month Name", "Day of Week", each Date.DayOfWeek([Date]), Int64.Type),
    #"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Week", "Day Name", each Date.DayOfWeekName([Date]), type text),
    #"Added Conditional Column" = Table.AddColumn(#"Inserted Day Name", "Is Weekend?", each if [Day of Week] = 6 then "Yes" else if [Day of Week] = 0 then "Yes" else "No"),
    #"Inserted Start of Month" = Table.AddColumn(#"Added Conditional Column", "Start of Month", each Date.StartOfMonth([Date]), type date),
    #"Added Custom" = Table.AddColumn(#"Inserted Start of Month", "Year Month", each [Year] * 100 + [Month]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Current Month", each let cm = Date.StartOfMonth(DateTime.LocalNow())
in Date.Year(cm) * 100 + Date.Month(cm)),
    #"Inserted Subtraction" = Table.AddColumn(#"Added Custom1", "Subtraction", each [Year Month] - [Current Month], type number),
    #"Added Conditional Column1" = Table.AddColumn(#"Inserted Subtraction", "Month Type", each if [Subtraction] = 0 then "This Month" else if [Subtraction] = 1 then "Next Month" else if [Subtraction] = -1 then "Previous Month" else "Other Month"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column1",{"Current Month", "Subtraction"})
in
    #"Removed Columns"

Una vez que tenga una configuración de DateTable, cree una relación entre las fechas de su tabla y la tabla de fechas.

luego simplemente cree un gráfico de líneas con Mes en el eje X, Suma de ganancias en el eje Y y Año en la leyenda

Corey_M_0-1714584075705.png

Lo último es agregar una segmentación en la que pueda colocar la categoría, lo que le permite filtrar a esa categoría.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.