Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!See when key Fabric features will launch and what’s already live, all in one place and always up to date. Explore the new Fabric roadmap
Hola,
Espero que vayais bien. Necesito vuestra ayuda. Ahora estoy empezando con el aprendizaje de funciones en M y me he quedado atascado con un supuesto.
Tabla Nº 1. tabla de ventas:
let
#"tabla de ventas"=
#table (
type table [Producto= text, Fecha=date, Importe= number],
{
{"Producto A",#date(2023,03,01),1000},
{"Producto A",#date(2023,03,02),500},
{"Producto A",#date(2023,03,03),750},
{"Producto B",#date(2023,03,01),2000},
{"Producto B",#date(2023,03,02),1500},
{"Producto B",#date(2023,03,03),1750},
{"Producto C",#date(2023,03,01),500},
{"Producto C",#date(2023,03,02),250},
{"Producto C",#date(2023,03,03),375}
}
)
in
#"tabla de ventas"
Tabla Nº 2. tabla de rangos
let
#"tabla de rangos"=
#table(
{"Producto","RangoFechas"},
{
{"Producto A",{"01/03/2023","03/03/2023"}},
{"Producto B",{"02/03/2023","03/03/2023"}},
{"Producto C",{"01/03/2023","02/03/2023"}}
}
)
in
#"tabla de rangos"
Necesito una funcion para poder conseguir este resultado en la tabla Nº2
Por favor necesito ayuda.
Gracias
Solved! Go to Solution.
@Syndicate_Admin , ajusté la fecha para adaptarla al formato estadounidense en la Tabla 2. He añadido esta nueva columna
let
_st = Date.From([DateRange]{0}),
_end = Date.From([DateRange]{1}),
_prd = [Product],
_data = List.Sum(Table.SelectRows(Table1,each [Date] >= _st and [Date]<=_end and [Product] =_prd )[Amount])
in
_data
También puede encontrar el archivo adjunto después de la firma
let
#"sales table"=
#table (
type table [Product= text, Date=date, Amount= number],
{
{"Product A",#date(2023,03,01),1000},
{"Product A",#date(2023,03,02),500},
{"Product A",#date(2023,03,03),750},
{"Product B",#date(2023,03,01),2000},
{"Product B",#date(2023,03,02),1500},
{"Product B",#date(2023,03,03),1750},
{"Product C",#date(2023,03,01),500},
{"Product C",#date(2023,03,02),250},
{"Product C",#date(2023,03,03),375}
}
),
#"range table"=
#table(
{"Product","DateRange"},
{
{"Product A",{"01/03/2023","03/03/2023"}},
{"Product B",{"02/03/2023","03/03/2023"}},
{"Product C",{"01/03/2023","02/03/2023"}}
}
),
Joined = Table.NestedJoin(#"range table", "Product", #"sales table", "Product", "Joined", JoinKind.LeftOuter),
#"Filtered Amount" = Table.ReplaceValue(Joined, each List.Transform([DateRange], Date.From), null, (x,y,z) => List.Sum(Table.SelectRows(x, each y{0}<=[Date] and [Date]<=y{1})[Amount]), {"Joined"})
in
#"Filtered Amount"
Hola,
Excelente solucion. Muchas gracias por tu ayuda. Seguimos aprendiendo de este maravilloso lenguaje M.
Seguimos en contacto.
let
#"sales table"=
#table (
type table [Product= text, Date=date, Amount= number],
{
{"Product A",#date(2023,03,01),1000},
{"Product A",#date(2023,03,02),500},
{"Product A",#date(2023,03,03),750},
{"Product B",#date(2023,03,01),2000},
{"Product B",#date(2023,03,02),1500},
{"Product B",#date(2023,03,03),1750},
{"Product C",#date(2023,03,01),500},
{"Product C",#date(2023,03,02),250},
{"Product C",#date(2023,03,03),375}
}
),
#"range table"=
#table(
{"Product","DateRange"},
{
{"Product A",{"01/03/2023","03/03/2023"}},
{"Product B",{"02/03/2023","03/03/2023"}},
{"Product C",{"01/03/2023","02/03/2023"}}
}
),
Joined = Table.NestedJoin(#"range table", "Product", #"sales table", "Product", "Joined", JoinKind.LeftOuter),
#"Filtered Amount" = Table.ReplaceValue(Joined, each List.Transform([DateRange], Date.From), null, (x,y,z) => List.Sum(Table.SelectRows(x, each y{0}<=[Date] and [Date]<=y{1})[Amount]), {"Joined"})
in
#"Filtered Amount"
@Syndicate_Admin , ajusté la fecha para adaptarla al formato estadounidense en la Tabla 2. He añadido esta nueva columna
let
_st = Date.From([DateRange]{0}),
_end = Date.From([DateRange]{1}),
_prd = [Product],
_data = List.Sum(Table.SelectRows(Table1,each [Date] >= _st and [Date]<=_end and [Product] =_prd )[Amount])
in
_data
También puede encontrar el archivo adjunto después de la firma