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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jarrod
Helper III
Helper III

Join Datasets Based on a common value and a range of numbers

Hi,

 

I am trying to join two datasets based on a matching column and then a number range. In SQL, I would do this with the following query. I am using Power BI Report Server so many not have access to latest features of Power BI.

 

 

 

SELECT
    SALES.Name
    ,SALES.Amount
    ,SALES.Time
    ,SalesLocation.Location
FROM
    SALES
    INNER JOIN SalesLocation ON Sales.Name = SalesLocation.Name 
    AND Sales.SaleTime > SalesLocation.StartTime
    AND Sales.SaleTime <= SalesLocation.EndTime

 

 

 

 

 

 Example dataset:

SALES

NameAmountTime
John15100
John101000
John111500
Jack6200
Jack25800

 

SalesLocation

NameLocationStartTimeEndTime
JohnWarehouse501300
JohnShop13012000
JackWarehouse501000

 

Desired Output

NameAmountSale Time In UTCLocation
John15100Warehouse
John101000Warehouse
John111500Shop
Jack6200Warehouse
Jack25800Warehouse
1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Jarrod 

You have to merge Sales with SalesLocatio based on Name and then expand the columns needed (locatin, start and end times). Once expanded, create a custom column to equivalent to this:

Sales.SaleTime > SalesLocation.StartTime
    AND Sales.SaleTime <= SalesLocation.EndTime

Please see attached pbix for details

 

danextian_0-1687499764098.png

danextian_2-1687499997382.png

 

Please see attached pbix










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
danextian
Super User
Super User

Hi @Jarrod 

You have to merge Sales with SalesLocatio based on Name and then expand the columns needed (locatin, start and end times). Once expanded, create a custom column to equivalent to this:

Sales.SaleTime > SalesLocation.StartTime
    AND Sales.SaleTime <= SalesLocation.EndTime

Please see attached pbix for details

 

danextian_0-1687499764098.png

danextian_2-1687499997382.png

 

Please see attached pbix










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks @danextian, this works perfectly. Unfortunately the performance of this is significantly worse when compared to completing the join in SQL Server. Might be best to let SQL handle this rather than Power BI.

 

Kudos to you though, thankyou! 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.