Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PowerBI DAX to lookup in another table between two dates

Hello all you beautiful people!

With lots of googling- still cannot solve this simple PowerBI trick. I want to build another table based on two tables – for timesheets – of which one table has the start and end dates of the timesheets month, and the other the timesheets themselves. I want to get a column added to the timesheet to state in which timesheet month it falls. (Timesheet month end is a few days before month’s last date, based on day of the week, etc)

Example tables:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Table cfgTimesheetMnth:

Period tsDateStart tsDateEnd
202302 2023-01-28 2023-02-24
202303 2023-02-25 2023-03-29
202304 2023-03-30 2023-04-26

Table erpPrjTimesheets :

EmpNo tsDate Hrs
100101 2023-03-05 7
100101 2023-03-30 6

Results Table. I then want to build a new table in PowerBI that needs to look as such:

Table verpPrjTimesheets:

EmpNo tsDate Hrs tsPeriod
100101 2023-03-05 7 202303
100101 2023-03-30 6 202304

The code in the dataview in PowerBI I started with are:

verpPrjTimesheets = 

VAR t1 = SELECTCOLUMNS(erpPrjTimesheets
            , "EmpNo"    , [EmpNo]
            , "tsDate"   , [tsDate]
            , "Hrs"      , [Hrs]
            , "tsPeriod" , LOOKUPVALUE(cfgTimesheetsMnth[Period], cfgTimesheetsMnth[tsDateEnd], erpPrjTimesheets[tsDate])
) RETURN 

t1

But the LOOKUPVALUE does not have a command to lookup between two date ranges. So above does not work.

What would be a better approach?

>Solution :

Here you go.

enter image description here

verpPrjTimesheets = 
ADDCOLUMNS(
    erpPrjTimesheets, 
    "tsPeriod",
    SELECTCOLUMNS(FILTER(cfgTimesheetMnth, erpPrjTimesheets[tsDate] >= cfgTimesheetMnth[tsDateStart] && erpPrjTimesheets[tsDate] <= cfgTimesheetMnth[tsDateEnd]), "tsPeriod", cfgTimesheetMnth[Period])
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading