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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
SvCappellen
Regular Visitor

Dynamic use of calculated value in power query

Hello everyone!

We have two lists with vacancies: 1. Open 2. Filled

For both files we calculate the processing times. For the file with open vacancies we calculate the processing time from posting date until today and for the filled vacancies from posting date till date filled in.

In de open vacancies we calculate with the average processing time of last year the expected startdate. Now we put this in a separate Excel file, but we want to make this dynamic.

We want to use per posting date the average processing time of the two months before that date.

Can anyone help us with that?

https://we.tl/t-125ZSaNwjZ


Kind regards,
Stephanie

1 ACCEPTED SOLUTION

Hi @SvCappellen ,

You can try this query based on your previous sample file:

let
    Bron = Table.Combine({Filled, Open}),
    #"Removed Columns" = Table.RemoveColumns(Bron,{"Processingtime 2020", "Expected startdate"}),
    #"Added Custom" = 
        Table.AddColumn(
            #"Removed Columns", "Average", each
                    if [Date filled] = null then 
                    let x = _ in
                    List.Average( 
                            Table.SelectRows(
                                #"Removed Columns",each
                                 
                                ([FunctionGroup] = x[FunctionGroup] and 
                                 [Posting date] <= x[Posting date] and 
                                 [Posting date] >= Date.AddMonths(x[Posting date],-2)
                                )
                                
                            )[Processing time] 
                    )
                    else null,type number
        ),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Expected Start time", each Date.From(Number.From([Posting date]) + [Average]),type date)
in
    #"Added Custom1"

3.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yingjl
Community Support
Community Support

Hi @SvCappellen ,

Based on your description, seems not certain what is your expected output.

Some questons in this case that want to know:

  1. "We want to use per posting date the average processing time of the two months before that date." What did 'two months before that date' mean?
  2. In your sample file, you combined the 'Open' table and the 'Filled' table as a single table. Did you want to create a column to calculate some 'average' value in this table or anything else?

 

Could you please consider taking an example from the sample file to explain the expected output in details so that members in the community could help you better.

 

Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 Thanks for the questions. 

1. We want to know for all dates what the average processing time is of the last two months. So for example for a posting date of July 30, 2021 we want to calculate the average processing times of all records that fall in the same function group with a posting date between April 30 and July 29.

  1. We want to create an extra column in the combined table or if it’s easier a separate (date)table with the average per date. That is our idea now, but maybe there is a better solution for this problem.


    So as an example:

    For the posting date Wednesday May 26, 2021 we want to calculate the average processing time from the filled and open vacancies between March 26 and May 25 to calculate the expected date filled for the open vacancy. 

 

Now we use to calculate the expected date filled the average processing time of last year from a separate Excel file that we manually fill. We want to get rid of that extra Excel file.

A example from the sample data:

FunctionFunctionGroupPosting dateDate filledProcessing timeAverageExpected startdate
AB12-11-20202-12-202020  
BA25-11-202018-12-202023  
BA25-11-202013-12-202018  
DB25-11-202015-12-202020  
DB1-12-202024-12-202023  
CB1-12-202019-12-202018  
CB1-12-202021-12-202020  
BA2-12-202025-12-202023  
CB4-12-202022-12-202018  
AA4-12-202024-12-202020  
BA21-12-202013-1-202123  
DB22-12-20209-1-202118  
AA24-12-202013-1-202120  
AA28-12-202020-1-202123  
AA31-12-202018-1-202118  
DB22-1-2021 186= AVERAGE PROCESSING TIME of the last two months before this post date= Post date + average 
DB28-1-2021 180= AVERAGE PROCESSING TIME of the last two months before this post date= Post date + average 
BB29-1-2021 17966,142857145-4-2021
DB16-2-2021 161= AVERAGE PROCESSING TIME of the last two months before this post date= Post date + average 
DB24-2-2021 153= AVERAGE PROCESSING TIME of the last two months before this post date= Post date + average 
AA26-2-2021 15120,518-3-2021
AA2-3-2021 147= AVERAGE PROCESSING TIME of the last two months before this post date= Post date + average 
CA3-3-2021 146= AVERAGE PROCESSING TIME of the last two months before this post date= Post date + average 

 

The Orange average is calculated from the orange records, the blue from the blue records. 

Hope this make our question more clear. 

Kind regards, 
Stephanie

 

Hi @SvCappellen ,

You can try this query based on your previous sample file:

let
    Bron = Table.Combine({Filled, Open}),
    #"Removed Columns" = Table.RemoveColumns(Bron,{"Processingtime 2020", "Expected startdate"}),
    #"Added Custom" = 
        Table.AddColumn(
            #"Removed Columns", "Average", each
                    if [Date filled] = null then 
                    let x = _ in
                    List.Average( 
                            Table.SelectRows(
                                #"Removed Columns",each
                                 
                                ([FunctionGroup] = x[FunctionGroup] and 
                                 [Posting date] <= x[Posting date] and 
                                 [Posting date] >= Date.AddMonths(x[Posting date],-2)
                                )
                                
                            )[Processing time] 
                    )
                    else null,type number
        ),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Expected Start time", each Date.From(Number.From([Posting date]) + [Average]),type date)
in
    #"Added Custom1"

3.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.