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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Nacho_P
Regular Visitor

Random Values for each row by calling a custom function

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"

 

 

 

 

 

 

3 REPLIES 3
Nacho_P
Regular Visitor

Just to showcase the result I'm getting rigth now..

Nacho_P_0-1652975043449.png

 

Hi! @Nacho_P ,

 

Can you please share the sample data and desired output that you need?

 

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

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.

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors