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
ChromeMystic
Helper I
Helper I

Can I create a lookup Table for Values between two dates in Powerquery?

I have solved this with DAX at the Moment but I would love to do it in PowerQuery, so I can create all my tables inside Dataflows.

I got a table with our KPI Values as well as the Start and end date.

 

 

Here is a Mockup on how it works.

StartDateEndDateKPINameGreenYellowRed
01.01.202131.12.2021KPIValue112

3

01.01.202131.12.2099KKPIValue259

16

01.01.202231.12.2099KPIValue11.52.5

3.5

 

In PowerBi Desktop I created a new Table that Pulls the Dates from my existing Datetable (although the Function on start and end Date I can easily Replicate in PowerQuery) and has Custom Rows that run the following DAX Code:

 

 

value1G = 
var __kpi = "kpiValue1" // set the KPI for this column
var __date = [Date] 
var __result = 
MAXX(
    FILTER(
        sedKPI,
            __date>=sedKPI[ValidFrom] && __date<=sedKPI[validTo] && sedKPI[KPI] = __kpi), // Filter if current date is between valid from and until
sedKPI[green] // select column that contains the value
)
return __result

 

 

This results in a lookuptable, that shows the current KPI Value for each day of my data. These I then use in my conditional Formatting and other functions for KPI breeches. As the KPI values change from time to time (normally once per year but we had changes that were done during a calendaryear as well) I don't just want to set a global value per KPI, as this would show the wrong results for older Data.

 

I found solutions on how to select data from a table based on one date with the Merge function in PowerQuery but I wasn't able to build something that checks wether todays date is between the start and enddate of my KPI Table and looks up the respective fields. Preferably I would do this with a custom function that gets the KPI value to look for as variable and then does the rest by itself.

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

Hi @ChromeMystic ,

According to your DAX formula, here's my PowerQuery solution.

Create a custom column.

= Table.SelectRows(sedKPI, 
    		(sedKPI) =>(sedKPI[ValidFrom] <= [Date]) and
       		(sedKPI[ValidTo]  >=  [Date]) and 
       		(sedKPI[KPI] = "KPIValue1")
        	)[Green]{0}

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
ChromeMystic
Helper I
Helper I

Thank you!! This worked as I need it. 

v-yanjiang-msft
Community Support
Community Support

Hi @ChromeMystic ,

According to your DAX formula, here's my PowerQuery solution.

Create a custom column.

= Table.SelectRows(sedKPI, 
    		(sedKPI) =>(sedKPI[ValidFrom] <= [Date]) and
       		(sedKPI[ValidTo]  >=  [Date]) and 
       		(sedKPI[KPI] = "KPIValue1")
        	)[Green]{0}

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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.

Top Solution Authors