This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
Hi everyone
It´s my 1st time asking for help to the community... Hoping for the best!
I need to define, for each row in a table, a random time between 4 defined parameters.
That random time is being calculated by calling, for each row, a custom Function (RandomTime), which works with those set parameters:
Custom3 = Table.AddColumn(Custom2, "Hora Corte Reparto AJ",
each
RandomTime(#"1er Slot Preparacion RNA",#"2do Slot Preparacion RNA",#"3er Slot Preparacion RNA",#"4to Slot Preparacion RNA")),
The calculation is being done correctly, but the problem is that the result for each row is the same, and I do not know where the problem lies....
Any ideas on how to solve this?
Much appreciated!
The custom functions are the following =>
(A,B,C,D as time) =>
let
RandomA = Number.From(A),
RandomB = Number.From(B),
RandomC= Number.From(C),
RandomD= Number.From(D),
Random1 =Number.RandomBetween(RandomA,RandomB),
Random2 =Number.RandomBetween(RandomC,RandomD),
ResultadoRandom=Number.RandomBetween(Random1,Random2),
Delta1=Number.Abs(Random1-ResultadoRandom),
Delta2= Number.Abs(Random2-ResultadoRandom),
RandomFinal= if Delta1<=Delta2
then Random1
else Random2,
RandomFinal2 = RoundownTime(Time.From(RandomFinal),TimeSlot)
in
RandomFinal2
(TimeToRound as time,TimeSlot as number ) =>
let
Source = TimeToRound,
#"Convert datetime to decimal" = Number.From(Source),
#"Upscale number" = #"Convert datetime to decimal"*(24*60/TimeSlot),
#"Round to nearest minute" = Number.Round(#"Upscale number"),
#"Downscale number" = #"Round to nearest minute" / (24*60/TimeSlot),
#"Convert back to time" = Time.From(#"Downscale number")
in
#"Convert back to time"
Just to showcase the result I'm getting rigth now..
Hi! @Nacho_P ,
Can you please share the sample data and desired output that you need?
Hi @AnkitKukreja , thank you for your reply.
The desired outcome is, for each row, a different randomized time based on the parameters which the custom function computes.
The problem I'm having is that, although I'm using an each statement, the random number is not generated for each row, but instead becomes fixed for the whole iteration.
The custom function requires 4 time parameters, and the result should be a random time that falls between A-B or between B-C.
Those time parameters currently are:
A)8:00
B)11:40
C)14:20
D)19:40
Hope this adds clarity to my question.
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.