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

Ingresos por contratos divididos en ingresos a lo largo de meses/años

Los ingresos se basan en posibles contratos y necesito pronosticar ingresos a lo largo de X años en función de la fecha de inicio/finalización.

Datos:

Id. de contratoNombre del contratoValorFecha de inicioFecha de finalizaciónMeses
id0001(Nombre)$1,000,00001/05/20202/05/202113
id0002(Nombre)$25,000,00005/01/202105/01/202548

Gráficamente necesito ser capaz de mostrar 2020, 2021, 2022, ect. ingresos basados en los contratos.

Intenté usar GENERATESERIES para hacer las filas basadas en los meses, pero no puedo establecerla como una variable y debe ser difícil?

GENERATE ( TableName, GENERATESERIES ( 0, TableName[Month], 1 ) )

Estoy en una pérdida en cómo crear estos datos para que no estén codificados de forma rígida y se puedan expandir fácilmente a medida que nuestra empresa crece. He probado varias exquaciones DAX y no puedo clavarlo.

Cualquier comentario en absoluto sería muy apreciado.

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

Hola, @JustinNoe

Es un placer responder por ti.

Puedes hacerlo en pq.

Así:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykwxMDAwVNJR8kvMTQXRhgZgAGQZGOobmOobGRiBOUZQDliNsVKsDlSvEVQviDYyRWg21Qfqh6qHc0CKDI2UYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Contract ID" = _t, #"Contract Name" = _t, Value = _t, #"Start Date" = _t, #"End Date" = _t, Months = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Contract ID", type text}, {"Contract Name", type text}, {"Value", Int64.Type}, {"Start Date", type date}, {"End Date", type date}, {"Months", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let 
x=(Date.Year([End Date])-Date.Year([Start Date]))*12+Date.Month([End Date])-Date.Month([Start Date]),
l=List.Generate(
    ()=>0,
    each _<=x,
    each _+1
)
in
l),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    Custom1 = Table.TransformRows(
#"Expanded Custom",
(x)=>
[
Contract ID=x[Contract ID],
Contract Name=x[Contract Name],
Value= let z=Table.RowCount(Table.SelectRows(#"Expanded Custom",(m)=>m[Contract ID]=x[Contract ID])) in x[Value]/z,
Start Date= let tab=Table.SelectRows(#"Expanded Custom",(y)=>y[Contract ID]=x[Contract ID]),min=Table.Min(tab,"Custom")[Custom] in if x[Custom]=min then x[Start Date] else Date.StartOfMonth( Date.AddMonths(x[Start Date],x[Custom])),
End Date=let tab=Table.SelectRows(#"Expanded Custom",(y)=>y[Contract ID]=x[Contract ID]),max=Table.Max(tab,"Custom")[Custom] in if x[Custom]=max then x[End Date] else Date.EndOfMonth( Date.AddMonths(x[Start Date],x[Custom])),
Month=x[Months]
]
),
    #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Contract ID", "Contract Name", "Value", "Start Date", "End Date", "Month"}, {"Contract ID", "Contract Name", "Value", "Start Date", "End Date", "Month"})
in
    #"Expanded Column1"

5.png

Aquí está mi archivo .pbix de ejemplo. Espero que ayude.

Si no resuelve su problema, por favor no dude en preguntarme.

Saludos

Janey Guo

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

View solution in original post

7 REPLIES 7
JustinNoe
Helper I
Helper I

El problema era el resultado de tener datos nulos, aunque los reemplaqué como un paso en la opción de transformación de datos.

Tan pronto como edité los datos del origen y se actualizó pude obtener los valores que se mostrarán correctamente.

Muchas gracias por tomarse el tiempo para ayudarme con esto.

v-janeyg-msft
Community Support
Community Support

Hola, @JustinNoe

Es un placer responder por ti.

Puedes hacerlo en pq.

Así:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykwxMDAwVNJR8kvMTQXRhgZgAGQZGOobmOobGRiBOUZQDliNsVKsDlSvEVQviDYyRWg21Qfqh6qHc0CKDI2UYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Contract ID" = _t, #"Contract Name" = _t, Value = _t, #"Start Date" = _t, #"End Date" = _t, Months = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Contract ID", type text}, {"Contract Name", type text}, {"Value", Int64.Type}, {"Start Date", type date}, {"End Date", type date}, {"Months", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let 
x=(Date.Year([End Date])-Date.Year([Start Date]))*12+Date.Month([End Date])-Date.Month([Start Date]),
l=List.Generate(
    ()=>0,
    each _<=x,
    each _+1
)
in
l),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    Custom1 = Table.TransformRows(
#"Expanded Custom",
(x)=>
[
Contract ID=x[Contract ID],
Contract Name=x[Contract Name],
Value= let z=Table.RowCount(Table.SelectRows(#"Expanded Custom",(m)=>m[Contract ID]=x[Contract ID])) in x[Value]/z,
Start Date= let tab=Table.SelectRows(#"Expanded Custom",(y)=>y[Contract ID]=x[Contract ID]),min=Table.Min(tab,"Custom")[Custom] in if x[Custom]=min then x[Start Date] else Date.StartOfMonth( Date.AddMonths(x[Start Date],x[Custom])),
End Date=let tab=Table.SelectRows(#"Expanded Custom",(y)=>y[Contract ID]=x[Contract ID]),max=Table.Max(tab,"Custom")[Custom] in if x[Custom]=max then x[End Date] else Date.EndOfMonth( Date.AddMonths(x[Start Date],x[Custom])),
Month=x[Months]
]
),
    #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Contract ID", "Contract Name", "Value", "Start Date", "End Date", "Month"}, {"Contract ID", "Contract Name", "Value", "Start Date", "End Date", "Month"})
in
    #"Expanded Column1"

5.png

Aquí está mi archivo .pbix de ejemplo. Espero que ayude.

Si no resuelve su problema, por favor no dude en preguntarme.

Saludos

Janey Guo

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

¡Muchas gracias por tomarse el tiempo para poner todo eso juntos para mí!

Me estoy enojendo con este mensaje de error y no puedo corregirlo. ¿Tiene alguna sugerencia sobre qué puede estar causando esto?

Screenshot 2020-12-10 101550.png

Hola, @JustinNoe

¿Puede compartir la captura de pantalla del resultado de custom1?

Tal vez el formato de resultado de custom1 entra en conflicto con el formato admitido por la función fromlist.

Saludos

Janey Guo

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

Tengo curiosidad si es un problema con mis datos. A pesar de que he entrado y reemplazado las valuues de "null" para algunas de las fechas de inicio / fin y el importe del valor (algunos contratos que no tenemos información en este momento), ¿sigue viendo el valor nulo original y, por lo tanto, lanzando el error?

Screenshot 2020-12-11 085310.png

Mis informes, ¿es esta la información a la que hace referencia?

Screenshot 2020-12-11 084000.png

Screenshot 2020-12-11 085310.png

Entré y verifiqué que no tengo ningún campo nulo en la tabla de datos, sólo para ver si eso puede haber causado problemas.

Fowmy
Super User
Super User

@JustinNoe

Usted se divide fácilmente y lo hace automatizado en Power Query, consulte mi blog y video para obtener más información.

https://www.youtube.com/watch?v=O3AnAKjRBLM&t=0s

https://excelfort.com/allocate-amount-monthly-excel-powerquery/

________________________

Si mi respuesta fue útil, haga clic en Aceptarla como la solución para ayudar a otros miembros a encontrarla útil

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


Sitio web 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

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.