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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
trwatts
Helper I
Helper I

Ayuda con la fórmula promedio

Hola a todos,

Estoy perplejo y estoy seguro de que esto es fácil de hacer, pero mi cabeza ha dejado de funcionar.

Tengo dos tablas, la tabla uno contiene tres columnas que contienen el número de días hábiles en el mes que operamos para cada tipo de reserva. Podemos llamarlos Tipo A, B y C.

Tabla Dos incluye una lista de reservas para el mes, los datos incluyen el tipo de reserva para el que fue la reserva en una sola columna.

Lo que quiero hacer es dividir el número de reservas en el mes en la tabla dos por el número de días hábiles de la tabla uno. La fórmula debe tener en cuenta el tipo de reserva.

Tengo una segmentación de datos para separar los tipos de reserva que necesitan actualizar el resultado.

Voy a mostrar el resultado en un gráfico de líneas.

Cualquier ayuda sería genial.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hola @trwatts ,

Según mi entender, quieres tener los días hábiles basados en el mismo Tipo y el mismo mes en dos tablas, ¿verdad?

Puede aplicar estos stpes para transformar Table1:

1. Seleccione Días de mes en la columna Mes -->despovorar otras columnas

2. Reemplace "tipo" y "Días en el mes" por

3. Baje y recorte los caracteres izquierdos

Toda la sintaxis M y la salida final de Table1 se muestran a continuación:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixN1zW0UNJRMgBiI2MwI1YnWik4tQBJ3AAu7p9cAhG3BGJDIxABFvfLL0NSbwRX75KaDBEHKzUGM0DiXol5uoZgMyyhkhBxt9QkiDiavb6JRckZSDKGcBnHgqLMHIgMyB5DkIyxUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month Days in  Month" = _t, #"type A Days in Month" = _t, #"type B Days in Month" = _t, #"type C Days in Month" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each "2018 "&[Month Days in  Month]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}, {"type A Days in Month", Int64.Type}, {"type B Days in Month", Int64.Type}, {"type C Days in Month", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Month Days in  Month"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Month Days in  Month"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Month Days in  Month", "type A Days in Month", "type B Days in Month", "type C Days in Month"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Reordered Columns", {"Month Days in  Month"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns","Days in Month","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","type","",Replacer.ReplaceText,{"Attribute"}),
    #"Lowercased Text" = Table.TransformColumns(#"Replaced Value1",{{"Attribute", Text.Lower, type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Lowercased Text",{{"Attribute", Text.Trim, type text}})
in
    #"Trimmed Text"

12.10.4.1.PNG

Ahora puede usar la siguiente fórmula para calcular los valores necesarios:

days =
LOOKUPVALUE (
    'Table1 (2)'[Value],
    [Month Days in  Month].[MonthNo], 'Table2'[Date Booked].[MonthNo],
    'Table1 (2)'[Attribute], 'Table2'[Session Type]
)
sumCost =
CALCULATE (
    SUM ( 'Table2'[Cost] ),
    ALLEXCEPT ( 'Table2', Table2[Date Booked].[MonthNo], 'Table2'[Session Type] )
)
Measure =
DIVIDE ( MAX ( Table2[sumCost] ), MAX ( 'Table2'[days] ) )

12.10.4.2.PNG

Aquí está el archivo pbix.

Si este post ayuda, entonces considera Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Saludos
Eyelyn Qin

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hola @trwatts ,

Según mi entender, quieres tener los días hábiles basados en el mismo Tipo y el mismo mes en dos tablas, ¿verdad?

Puede aplicar estos stpes para transformar Table1:

1. Seleccione Días de mes en la columna Mes -->despovorar otras columnas

2. Reemplace "tipo" y "Días en el mes" por

3. Baje y recorte los caracteres izquierdos

Toda la sintaxis M y la salida final de Table1 se muestran a continuación:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixN1zW0UNJRMgBiI2MwI1YnWik4tQBJ3AAu7p9cAhG3BGJDIxABFvfLL0NSbwRX75KaDBEHKzUGM0DiXol5uoZgMyyhkhBxt9QkiDiavb6JRckZSDKGcBnHgqLMHIgMyB5DkIyxUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month Days in  Month" = _t, #"type A Days in Month" = _t, #"type B Days in Month" = _t, #"type C Days in Month" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each "2018 "&[Month Days in  Month]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}, {"type A Days in Month", Int64.Type}, {"type B Days in Month", Int64.Type}, {"type C Days in Month", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Month Days in  Month"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Month Days in  Month"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Month Days in  Month", "type A Days in Month", "type B Days in Month", "type C Days in Month"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Reordered Columns", {"Month Days in  Month"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns","Days in Month","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","type","",Replacer.ReplaceText,{"Attribute"}),
    #"Lowercased Text" = Table.TransformColumns(#"Replaced Value1",{{"Attribute", Text.Lower, type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Lowercased Text",{{"Attribute", Text.Trim, type text}})
in
    #"Trimmed Text"

12.10.4.1.PNG

Ahora puede usar la siguiente fórmula para calcular los valores necesarios:

days =
LOOKUPVALUE (
    'Table1 (2)'[Value],
    [Month Days in  Month].[MonthNo], 'Table2'[Date Booked].[MonthNo],
    'Table1 (2)'[Attribute], 'Table2'[Session Type]
)
sumCost =
CALCULATE (
    SUM ( 'Table2'[Cost] ),
    ALLEXCEPT ( 'Table2', Table2[Date Booked].[MonthNo], 'Table2'[Session Type] )
)
Measure =
DIVIDE ( MAX ( Table2[sumCost] ), MAX ( 'Table2'[days] ) )

12.10.4.2.PNG

Aquí está el archivo pbix.

Si este post ayuda, entonces considera Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Saludos
Eyelyn Qin

Fowmy
Super User
Super User

@trwatts

¿Puede compartir algunos datos de muestra y el resultado esperado para tener una comprensión clara de su pregunta?
Puedes guardar tus archivos en OneDrive, Google Drive o cualquier otra plataforma de uso compartido en la nube y compartir el enlace aquí.
____________________________________
¿Cómo pegar datos de muestra con su pregunta?
¿Cómo obtener respuestas a sus preguntas rápidamente?

_____________________________________
¿He respondido a tu pregunta? Marque este post como una solución, esto ayudará a otros!.

Haga clic en el icono Thumbs-Up si le gusta esta respuesta 🙂

Youtube Linkedin

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

I went to put the data in as a table but it wouldn't let me? I have added commas where there would normally be a column.

Data set 1

Month Days in Month, type A Days in Month, type B Days in Month, type C days in month
Aug-18, 0, 23, 0
Sep-18 0, 20, 0,
Oct-18 9 13 1
Nov-18 0 22 0
Dec-18 2 13 2
Jan-19 19 2 2
Feb-19 0 20 0
Mar-19 0 21 0
Apr-19 8 11 3


Table 2

Service Name, Date Booked, Cost, Service ID, Session Type
Location A, 3/07/2018, $23.00, 8562, a 
Location A, 4/07/2018, $26.00, 8562, b
Location A 24/07/2018 $26.00 8562 b
Location A 25/07/2018 $26.00 8562 b
Location A 31/07/2018 $31.00 8562 c
Location B 1/08/2018 $26.00 8562 b
Location B 7/08/2018 $31.00 8562 c
Location B 8/08/2018 $23.00 8562 a 
Location C 14/08/2018 $23.00 8562 a
Location C 15/08/2018 $23.00 8562 a
Location C 21/08/2018 $31.00 8562 c
Location C 22/08/2018 $26.00 8562 b
Location C 28/08/2018 $26.00 8562 b
Location C 29/08/2018 $26.00 8562 b
Location D 4/09/2018 $31.00 8562 c



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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